From 30d077b0a649fabccd4324ba219250c2ddb96cae Mon Sep 17 00:00:00 2001 From: zhongwuzw Date: Fri, 10 Aug 2018 22:53:13 +0800 Subject: [PATCH] Make callbacks of download more readable --- SDWebImage/SDWebImageDownloaderOperation.m | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/SDWebImage/SDWebImageDownloaderOperation.m b/SDWebImage/SDWebImageDownloaderOperation.m index 2690beab..a6c13fa7 100644 --- a/SDWebImage/SDWebImageDownloaderOperation.m +++ b/SDWebImage/SDWebImageDownloaderOperation.m @@ -105,15 +105,10 @@ typedef NSMutableDictionary SDCallbacksDictionary; - (nullable NSArray *)callbacksForKey:(NSString *)key { LOCK(self.callbacksLock); - NSArray *callbackBlocks = [self.callbackBlocks copy]; + NSMutableArray *callbacks = [[self.callbackBlocks valueForKey:key] mutableCopy]; UNLOCK(self.callbacksLock); - NSMutableArray *callbacks = [NSMutableArray arrayWithCapacity:callbackBlocks.count]; - for (SDCallbacksDictionary *callbacksDic in callbackBlocks) { - id callback = callbacksDic[key]; - if (callback) { - [callbacks addObject:callback]; - } - } + // We need to remove [NSNull null] because there might not always be a progress block for each callback + [callbacks removeObjectIdenticalTo:[NSNull null]]; return [callbacks copy]; // strip mutability here }