From c7a160a9e7cbc5312e30ef74336ff84d0c6626a5 Mon Sep 17 00:00:00 2001 From: Christopher Snowhill Date: Mon, 3 Mar 2025 22:22:02 -0800 Subject: [PATCH] Improvement: Hopefully improve tag loading speed Hopefully this works for most ASCII and UTF-8 tags, and continues to work for weird tag encodings. Signed-off-by: Christopher Snowhill --- Audio/Plugin.h | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Audio/Plugin.h b/Audio/Plugin.h index a4077a23d..c88eeb942 100644 --- a/Audio/Plugin.h +++ b/Audio/Plugin.h @@ -108,7 +108,13 @@ static NSString *guess_encoding_of_string(const char *input) { NSString *ret = @""; - NSData *stringData = [NSData dataWithBytes:input length:strlen(input)]; - [NSString stringEncodingForData:stringData encodingOptions:nil convertedString:&ret usedLossyConversion:nil]; + @try { + ret = [NSString stringWithUTF8String:input]; + } + @catch(id anException) { + // This method is incredibly slow + NSData *stringData = [NSData dataWithBytes:input length:strlen(input)]; + [NSString stringEncodingForData:stringData encodingOptions:nil convertedString:&ret usedLossyConversion:nil]; + } return ret; }