From 1b4ec4dc4d2d0cee3a6a723f17b484fa37668b7b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Sat, 14 Jan 2012 16:07:58 +0000 Subject: [PATCH] search for folder nodes concurrently when generating a torrent's file list --- macosx/Torrent.m | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/macosx/Torrent.m b/macosx/Torrent.m index f6b82c89d..eec2d084b 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1710,10 +1710,14 @@ int trashDataFile(const char * filename) if ([pathComponents count] > 2) { //determine if folder node already exists - FileListNode * node; - for (node in fileList) - if ([[node name] isEqualToString: name] && [node isFolder]) - break; + __block FileListNode * node = nil; + [fileList enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: ^(FileListNode * searchNode, NSUInteger idx, BOOL * stop) { + if ([[searchNode name] isEqualToString: name] && [searchNode isFolder]) + { + node = searchNode; + *stop = YES; + } + }]; if (!node) { @@ -1722,8 +1726,7 @@ int trashDataFile(const char * filename) [node release]; } - NSMutableArray * trimmedComponents = [NSMutableArray arrayWithArray: [pathComponents subarrayWithRange: - NSMakeRange(2, [pathComponents count]-2)]]; + NSMutableArray * trimmedComponents = [NSMutableArray arrayWithArray: [pathComponents subarrayWithRange: NSMakeRange(2, [pathComponents count]-2)]]; [node insertIndex: i withSize: file->length]; [self insertPath: trimmedComponents forParent: node fileSize: file->length index: i flatList: flatFileList]; @@ -1758,6 +1761,7 @@ int trashDataFile(const char * filename) NSString * name = [components objectAtIndex: 0]; const BOOL isFolder = [components count] > 1; + //determine if folder node already exists __block FileListNode * node = nil; if (isFolder) {