Don't create a new image for each completion block

This commit is contained in:
Matt Galloway 2014-09-08 20:15:43 +01:00
parent b00b09e706
commit ae91053a80
1 changed files with 15 additions and 9 deletions

View File

@ -387,10 +387,12 @@ static NSString *const kCompletedCallbackKey = @"completed";
if (![[NSURLCache sharedURLCache] cachedResponseForRequest:_request]) {
responseFromCached = NO;
}
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
if (completionBlocks.count > 0) {
if (self.options & SDWebImageDownloaderIgnoreCachedResponse && responseFromCached) {
completionBlock(nil, nil, nil, YES);
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
completionBlock(nil, nil, nil, YES);
}
} else if (self.imageData) {
UIImage *image = [UIImage sd_imageWithData:self.imageData];
NSString *key = [[SDWebImageManager sharedManager] cacheKeyForURL:self.request.URL];
@ -402,14 +404,18 @@ static NSString *const kCompletedCallbackKey = @"completed";
image = [UIImage decodedImageWithImage:image];
}
}
if (CGSizeEqualToSize(image.size, CGSizeZero)) {
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
}
else {
completionBlock(image, self.imageData, nil, YES);
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
if (CGSizeEqualToSize(image.size, CGSizeZero)) {
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Downloaded image has 0 pixels"}], YES);
}
else {
completionBlock(image, self.imageData, nil, YES);
}
}
} else {
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
for (SDWebImageDownloaderCompletedBlock completionBlock in completionBlocks) {
completionBlock(nil, nil, [NSError errorWithDomain:SDWebImageErrorDomain code:0 userInfo:@{NSLocalizedDescriptionKey : @"Image data is nil"}], YES);
}
}
}
[self done];