concurrent enumeration when generating a torrent's file list

This commit is contained in:
Mitchell Livingston 2012-01-09 00:57:50 +00:00
parent f05360e5a3
commit a0abfd79c0
2 changed files with 10 additions and 5 deletions

View File

@ -33,7 +33,9 @@
[coloredImage lockFocus];
[color set];
NSRectFillUsingOperation(NSMakeRect(0.0, 0.0, [coloredImage size].width, [coloredImage size].height), NSCompositeSourceAtop);
const NSSize size = [coloredImage size];
NSRectFillUsingOperation(NSMakeRect(0.0, 0.0, size.width, size.height), NSCompositeSourceAtop);
[coloredImage unlockFocus];

View File

@ -1761,9 +1761,11 @@ int trashDataFile(const char * filename)
FileListNode * node = nil;
if (isFolder)
{
for (node in [parent children])
if ([[node name] isEqualToString: name] && [node isFolder])
break;
const NSUInteger nodeIndex = [[parent children] indexOfObjectWithOptions: NSEnumerationConcurrent passingTest: ^BOOL(FileListNode * searchNode, NSUInteger idx, BOOL * stop) {
return [[searchNode name] isEqualToString: name] && [searchNode isFolder];
}];
if (nodeIndex != NSNotFound)
node = [[parent children] objectAtIndex: nodeIndex];
}
//create new folder or file if it doesn't already exist
@ -1796,9 +1798,10 @@ int trashDataFile(const char * filename)
NSSortDescriptor * descriptor = [NSSortDescriptor sortDescriptorWithKey: @"name" ascending: YES selector: @selector(localizedStandardCompare:)];
[fileNodes sortUsingDescriptors: [NSArray arrayWithObject: descriptor]];
for (FileListNode * node in fileNodes)
[fileNodes enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * node, NSUInteger idx, BOOL * stop) {
if ([node isFolder])
[self sortFileList: [node children]];
}];
}
- (void) startQueue