Skip to content

Commit 2cd8790

Browse files
donhollymallorypaine
authored andcommitted
Use NSJSONSerialization instead of NSPropertyListSerialization to improve the speed serializing Image Table metadata before writing to disk. This change is backward compatible with previous Image Tables
1 parent ff43eb4 commit 2cd8790

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

FastImageCache/FICImageTable.m

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -702,7 +702,7 @@ - (void)saveMetadata {
702702
return;
703703
}
704704

705-
NSData *data = [NSPropertyListSerialization dataWithPropertyList:metadataDictionary format:NSPropertyListBinaryFormat_v1_0 options:0 error:NULL];
705+
NSData *data = [NSJSONSerialization dataWithJSONObject:metadataDictionary options:kNilOptions error:NULL];
706706

707707
// Cancel disk writing if a new metadata version is queued to be saved
708708
if (metadataVersion != _metadataVersion) {
@@ -721,7 +721,14 @@ - (void)_loadMetadata {
721721
NSString *metadataFilePath = [self metadataFilePath];
722722
NSData *metadataData = [NSData dataWithContentsOfURL:[NSURL fileURLWithPath:metadataFilePath] options:NSDataReadingMappedAlways error:NULL];
723723
if (metadataData != nil) {
724-
NSDictionary *metadataDictionary = (NSDictionary *)[NSPropertyListSerialization propertyListWithData:metadataData options:0 format:NULL error:NULL];
724+
NSDictionary *metadataDictionary = (NSDictionary *)[NSJSONSerialization JSONObjectWithData:metadataData options:kNilOptions error:NULL];
725+
726+
if (!metadataDictionary) {
727+
// The image table was likely previously stored as a .plist
728+
// We'll read it into memory as a .plist and later store it (during -saveMetadata) using NSJSONSerialization for performance reasons
729+
metadataDictionary = (NSDictionary *)[NSPropertyListSerialization propertyListWithData:metadataData options:0 format:NULL error:NULL];
730+
}
731+
725732
NSDictionary *formatDictionary = [metadataDictionary objectForKey:FICImageTableFormatKey];
726733
if ([formatDictionary isEqualToDictionary:_imageFormatDictionary] == NO) {
727734
// Something about this image format has changed, so the existing metadata is no longer valid. The image table file

0 commit comments

Comments
 (0)