From 480700e835eb9779eb022170be632430f73b5951 Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Tue, 31 Jan 2012 04:22:51 +0000 Subject: [PATCH] remove redundant code in Torrent's canChangeDownloadCheckForFile:, and enumerate of the files in canChangeDownloadCheckForFiles: concurrently. --- macosx/Controller.m | 1 + macosx/Torrent.m | 19 +++++++++---------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/macosx/Controller.m b/macosx/Controller.m index 3f86261f5..413ba6ea3 100644 --- a/macosx/Controller.m +++ b/macosx/Controller.m @@ -409,6 +409,7 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy BOOL foundSortItem = NO; for (NSMenuItem * item in [fSortMenu itemArray]) { + //assume all sort items are together and the Queue Order item is first if ([item action] == @selector(setSort:) && [item tag] != SORT_ORDER_TAG) { [sortMenuItems addObject: item]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index d30817c3a..a6378c717 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1381,13 +1381,7 @@ int trashDataFile(const char * filename) { NSAssert2(index < [self fileCount], @"Index %d is greater than file count %d", index, [self fileCount]); - if ([self fileCount] == 1 || [self isComplete]) - return NO; - - if (!fFileStat) - [self updateFileStat]; - - return fFileStat[index].progress < 1.0; + return [self canChangeDownloadCheckForFiles: [NSIndexSet indexSetWithIndex: index]]; } - (BOOL) canChangeDownloadCheckForFiles: (NSIndexSet *) indexSet @@ -1398,10 +1392,15 @@ int trashDataFile(const char * filename) if (!fFileStat) [self updateFileStat]; - for (NSUInteger index = [indexSet firstIndex]; index != NSNotFound; index = [indexSet indexGreaterThanIndex: index]) + __block BOOL canChange = NO; + [indexSet enumerateIndexesWithOptions: NSEnumerationConcurrent usingBlock: ^(NSUInteger index, BOOL *stop) { if (fFileStat[index].progress < 1.0) - return YES; - return NO; + { + canChange = YES; + *stop = YES; + } + }]; + return canChange; } - (NSInteger) checkForFiles: (NSIndexSet *) indexSet