Skip to content

Commit

Permalink
Merge pull request #17 from jmah/jmah/mini-optimization
Browse files Browse the repository at this point in the history
Optimize cancelling operations a little
  • Loading branch information
garrettmoon committed Aug 1, 2015
2 parents bbf05de + ffd92b7 commit 053ee6d
Showing 1 changed file with 10 additions and 16 deletions.
26 changes: 10 additions & 16 deletions Pod/Classes/PINRemoteImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ @interface PINRemoteImageManager () <PINURLSessionManagerDelegate>
@property (nonatomic, strong) PINURLSessionManager *sessionManager;
@property (nonatomic, assign) NSTimeInterval timeout;
@property (nonatomic, strong) NSMutableDictionary *tasks;
@property (nonatomic, strong) NSMutableArray *canceledTasks;
@property (nonatomic, strong) NSMutableSet *canceledTasks;
@property (nonatomic, strong) NSArray *progressThresholds;
@property (nonatomic, assign) NSTimeInterval estimatedRemainingTimeThreshold;
@property (nonatomic, strong) dispatch_queue_t callbackQueue;
Expand Down Expand Up @@ -164,7 +164,7 @@ - (instancetype)init
_lowQualityBPSThreshold = 50000; // approximately edge speeds
_shouldUpgradeLowQualityImages = NO;
self.tasks = [[NSMutableDictionary alloc] init];
self.canceledTasks = [[NSMutableArray alloc] init];
self.canceledTasks = [[NSMutableSet alloc] init];
self.taskQOS = [[NSMutableArray alloc] initWithCapacity:5];
}
return self;
Expand Down Expand Up @@ -886,21 +886,15 @@ - (void)cancelTaskWithUUID:(NSUUID *)UUID
typeof(self) strongSelf = weakSelf;
//find the task associated with the UUID. This might be spead up by storing a mapping of UUIDs to tasks
[strongSelf lock];
PINRemoteImageTask *taskToEvaluate = nil;
NSString *taskKey = nil;
for (NSString *key in [strongSelf.tasks allKeys]) {
PINRemoteImageTask *task = strongSelf.tasks[key];
for (NSUUID *blockUUID in [task.callbackBlocks allKeys]) {
if ([blockUUID isEqual:UUID]) {
taskToEvaluate = task;
taskKey = key;
break;
}
}
if (taskKey) {
break;
__block PINRemoteImageTask *taskToEvaluate = nil;
__block NSString *taskKey = nil;
[strongSelf.tasks enumerateKeysAndObjectsUsingBlock:^(NSString *key, PINRemoteImageTask *task, BOOL *stop) {
if (task.callbackBlocks[UUID]) {
taskToEvaluate = task;
taskKey = key;
*stop = YES;
}
}
}];

if (taskToEvaluate == nil) {
//maybe task hasn't been added to task list yet, add it to canceled tasks
Expand Down

0 comments on commit 053ee6d

Please sign in to comment.