Skip to content

Commit 55fcf55

Browse files
committed
Merge remote-tracking branch 'path/master'
2 parents 527d71b + 417084e commit 55fcf55

File tree

2 files changed

+50
-44
lines changed

2 files changed

+50
-44
lines changed

FastImageCache/FastImageCache/FastImageCache/FICImageCache.m

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,18 +214,20 @@ - (BOOL)_retrieveImageForEntity:(id <FICEntity>)entity withFormatName:(NSString
214214
}
215215

216216
if (needsToFetch) {
217-
UIImage *image;
218-
if ([entity respondsToSelector:@selector(imageForFormat:)]){
219-
FICImageFormat *format = [self formatWithName:formatName];
220-
image = [entity imageForFormat:format];
221-
}
222-
223-
if (image){
224-
[self _imageDidLoad:image forURL:sourceImageURL];
225-
} else if (_delegateImplementsWantsSourceImageForEntityWithFormatNameCompletionBlock){
226-
[_delegate imageCache:self wantsSourceImageForEntity:entity withFormatName:formatName completionBlock:^(UIImage *sourceImage) {
227-
[self _imageDidLoad:sourceImage forURL:sourceImageURL];
228-
}];
217+
@autoreleasepool {
218+
UIImage *image;
219+
if ([entity respondsToSelector:@selector(imageForFormat:)]){
220+
FICImageFormat *format = [self formatWithName:formatName];
221+
image = [entity imageForFormat:format];
222+
}
223+
224+
if (image){
225+
[self _imageDidLoad:image forURL:sourceImageURL];
226+
} else if (_delegateImplementsWantsSourceImageForEntityWithFormatNameCompletionBlock){
227+
[_delegate imageCache:self wantsSourceImageForEntity:entity withFormatName:formatName completionBlock:^(UIImage *sourceImage) {
228+
[self _imageDidLoad:sourceImage forURL:sourceImageURL];
229+
}];
230+
}
229231
}
230232
}
231233
} else {

FastImageCache/FastImageCache/FastImageCache/FICImageTable.m

Lines changed: 36 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -681,43 +681,47 @@ - (NSNumber *)_numberForEntryAtIndex:(NSInteger)index {
681681
#pragma mark - Working with Metadata
682682

683683
- (void)saveMetadata {
684-
[_lock lock];
685-
686-
NSDictionary *metadataDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
687-
[_indexMap copy], FICImageTableIndexMapKey,
688-
[_sourceImageMap copy], FICImageTableContextMapKey,
689-
[[_MRUEntries array] copy], FICImageTableMRUArrayKey,
690-
[_imageFormatDictionary copy], FICImageTableFormatKey, nil];
684+
@autoreleasepool {
685+
[_lock lock];
686+
687+
NSDictionary *metadataDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
688+
[_indexMap copy], FICImageTableIndexMapKey,
689+
[_sourceImageMap copy], FICImageTableContextMapKey,
690+
[[_MRUEntries array] copy], FICImageTableMRUArrayKey,
691+
[_imageFormatDictionary copy], FICImageTableFormatKey, nil];
691692

692-
__block int32_t metadataVersion = OSAtomicIncrement32(&_metadataVersion);
693+
__block int32_t metadataVersion = OSAtomicIncrement32(&_metadataVersion);
693694

694-
[_lock unlock];
695-
696-
static dispatch_queue_t __metadataQueue = nil;
697-
static dispatch_once_t onceToken;
698-
dispatch_once(&onceToken, ^{
699-
__metadataQueue = dispatch_queue_create("com.path.FastImageCache.ImageTableMetadataQueue", NULL);
700-
});
701-
702-
dispatch_async(__metadataQueue, ^{
703-
// Cancel serialization if a new metadata version is queued to be saved
704-
if (metadataVersion != _metadataVersion) {
705-
return;
706-
}
695+
[_lock unlock];
696+
697+
static dispatch_queue_t __metadataQueue = nil;
698+
static dispatch_once_t onceToken;
699+
dispatch_once(&onceToken, ^{
700+
__metadataQueue = dispatch_queue_create("com.path.FastImageCache.ImageTableMetadataQueue", NULL);
701+
});
702+
703+
dispatch_async(__metadataQueue, ^{
704+
// Cancel serialization if a new metadata version is queued to be saved
705+
if (metadataVersion != _metadataVersion) {
706+
return;
707+
}
707708

708-
NSData *data = [NSJSONSerialization dataWithJSONObject:metadataDictionary options:kNilOptions error:NULL];
709+
@autoreleasepool {
710+
NSData *data = [NSJSONSerialization dataWithJSONObject:metadataDictionary options:kNilOptions error:NULL];
709711

710-
// Cancel disk writing if a new metadata version is queued to be saved
711-
if (metadataVersion != _metadataVersion) {
712-
return;
713-
}
712+
// Cancel disk writing if a new metadata version is queued to be saved
713+
if (metadataVersion != _metadataVersion) {
714+
return;
715+
}
714716

715-
BOOL fileWriteResult = [data writeToFile:[self metadataFilePath] atomically:NO];
716-
if (fileWriteResult == NO) {
717-
NSString *message = [NSString stringWithFormat:@"*** FIC Error: %s couldn't write metadata for format %@", __PRETTY_FUNCTION__, [_imageFormat name]];
718-
[self.imageCache _logMessage:message];
719-
}
720-
});
717+
BOOL fileWriteResult = [data writeToFile:[self metadataFilePath] atomically:NO];
718+
if (fileWriteResult == NO) {
719+
NSString *message = [NSString stringWithFormat:@"*** FIC Error: %s couldn't write metadata for format %@", __PRETTY_FUNCTION__, [_imageFormat name]];
720+
[self.imageCache _logMessage:message];
721+
}
722+
}
723+
});
724+
}
721725
}
722726

723727
- (void)_loadMetadata {

0 commit comments

Comments
 (0)