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 <kode54@gmail.com>
This commit is contained in:
Christopher Snowhill 2025-03-03 22:22:02 -08:00
parent 2f9d7fe66d
commit c7a160a9e7

View file

@ -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;
}