From f3add380e555c485fd6530f4dd7757cca5e9004b Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 26 Dec 2008 07:25:17 +0000 Subject: [PATCH] eliminate some more enumerator objects --- macosx/DragOverlayWindow.m | 4 +--- macosx/FileOutlineController.m | 4 +--- macosx/FileOutlineView.m | 4 +--- macosx/PrefsController.m | 21 ++++++++------------- macosx/Torrent.m | 15 +++++---------- macosx/TorrentGroup.m | 12 +++--------- 6 files changed, 19 insertions(+), 41 deletions(-) diff --git a/macosx/DragOverlayWindow.m b/macosx/DragOverlayWindow.m index fd79b8d9f..35028f83b 100644 --- a/macosx/DragOverlayWindow.m +++ b/macosx/DragOverlayWindow.m @@ -81,9 +81,7 @@ BOOL folder; NSInteger fileCount = 0; - NSString * file; - NSEnumerator * enumerator = [files objectEnumerator]; - while ((file = [enumerator nextObject])) + for (NSString * file in files) { if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame) { diff --git a/macosx/FileOutlineController.m b/macosx/FileOutlineController.m index e12ff1ea0..951ef8150 100644 --- a/macosx/FileOutlineController.m +++ b/macosx/FileOutlineController.m @@ -113,9 +113,7 @@ typedef enum { NSMutableArray * list = [NSMutableArray arrayWithCapacity: [fTorrent fileCount]]; - NSEnumerator * enumerator = [[fTorrent flatFileList] objectEnumerator]; - FileListNode * node; - while ((node = [enumerator nextObject])) + for (FileListNode * node in [fTorrent flatFileList]) if ([[node name] rangeOfString: fFilterText options: NSCaseInsensitiveSearch].location != NSNotFound) [list addObject: node]; diff --git a/macosx/FileOutlineView.m b/macosx/FileOutlineView.m index 5b02b3684..a1c421da2 100644 --- a/macosx/FileOutlineView.m +++ b/macosx/FileOutlineView.m @@ -126,9 +126,7 @@ { [super updateTrackingAreas]; - NSEnumerator * enumerator = [[self trackingAreas] objectEnumerator]; - NSTrackingArea * area; - while ((area = [enumerator nextObject])) + for (NSTrackingArea * area in [self trackingAreas]) { if ([area owner] == self && [[area userInfo] objectForKey: @"Row"]) [self removeTrackingArea: area]; diff --git a/macosx/PrefsController.m b/macosx/PrefsController.m index 9e04c4de3..5c5e683d1 100644 --- a/macosx/PrefsController.m +++ b/macosx/PrefsController.m @@ -406,21 +406,20 @@ tr_session * fHandle; NSArray * directories = [NSArray arrayWithObjects: @"/System/Library/Sounds", @"/Library/Sounds", @"Library/Sounds", nil]; - BOOL isDirectory; - NSString * directory; - NSEnumerator * enumerator = [directories objectEnumerator]; - while ((directory = [enumerator nextObject])) + for (NSString * directory in directories) + { + BOOL isDirectory; if ([[NSFileManager defaultManager] fileExistsAtPath: directory isDirectory: &isDirectory] && isDirectory) { - NSString * sound; - NSEnumerator * soundEnumerator = [[[NSFileManager defaultManager] directoryContentsAtPath: directory] objectEnumerator]; - while ((sound = [soundEnumerator nextObject])) + NSArray * directoryContents = [[NSFileManager defaultManager] directoryContentsAtPath: directory]; + for (NSString * sound in directoryContents) { sound = [sound stringByDeletingPathExtension]; if ([NSSound soundNamed: sound]) [sounds addObject: sound]; } } + } return sounds; } @@ -945,9 +944,7 @@ tr_session * fHandle; if ([components count] == 4) { valid = true; - NSEnumerator * enumerator = [components objectEnumerator]; - NSString * component; - while ((component = [enumerator nextObject])) + for (NSString * component in components) { if ([component isEqualToString: @"*"]) [newComponents addObject: component]; @@ -1142,9 +1139,7 @@ tr_session * fHandle; { NSToolbar * toolbar = [window toolbar]; NSString * itemIdentifier = [toolbar selectedItemIdentifier]; - NSEnumerator * enumerator = [[toolbar items] objectEnumerator]; - NSToolbarItem * item; - while ((item = [enumerator nextObject])) + for (NSToolbarItem * item in [toolbar items]) if ([[item itemIdentifier] isEqualToString: itemIdentifier]) { [window setTitle: [item label]]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index 69ce5caeb..ae1ca40b0 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1744,9 +1744,8 @@ int trashDataFile(const char * filename) if ([pathComponents count] > 0) { //determine if folder node already exists - NSEnumerator * enumerator = [fileList objectEnumerator]; - FileListNode * node; - while ((node = [enumerator nextObject])) + FileListNode * node = nil; + for (node in fileList) if ([[node name] isEqualToString: name] && [node isFolder]) break; @@ -1795,8 +1794,7 @@ int trashDataFile(const char * filename) FileListNode * node = nil; if (isFolder) { - NSEnumerator * enumerator = [[parent children] objectEnumerator]; - while ((node = [enumerator nextObject])) + for (node in [parent children]) if ([[node name] isEqualToString: name] && [node isFolder]) break; } @@ -1944,17 +1942,14 @@ int trashDataFile(const char * filename) { //get count NSInteger count = 0; - NSEnumerator * enumerator = [trackers objectEnumerator]; - id object; - while ((object = [enumerator nextObject])) + for (id object in trackers) if (![object isKindOfClass: [NSNumber class]]) count++; //recreate the tracker structure tr_tracker_info * trackerStructs = tr_new(tr_tracker_info, count); NSInteger tier = 0, i = 0; - enumerator = [trackers objectEnumerator]; - while ((object = [enumerator nextObject])) + for (id object in trackers) { if (![object isKindOfClass: [NSNumber class]]) { diff --git a/macosx/TorrentGroup.m b/macosx/TorrentGroup.m index 5f2f0a688..a78cf2dae 100644 --- a/macosx/TorrentGroup.m +++ b/macosx/TorrentGroup.m @@ -57,9 +57,7 @@ - (CGFloat) ratio { uint64_t uploaded = 0, downloaded = 0; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) { uploaded += [torrent uploadedTotal]; downloaded += [torrent downloadedTotal]; @@ -71,9 +69,7 @@ - (CGFloat) uploadRate { CGFloat rate = 0.0f; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) rate += [torrent uploadRate]; return rate; @@ -82,9 +78,7 @@ - (CGFloat) downloadRate { CGFloat rate = 0.0f; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) rate += [torrent downloadRate]; return rate;