From c89caf9cb4299900bb2afe58f1c29e8b218268ba Mon Sep 17 00:00:00 2001 From: Mitchell Livingston Date: Fri, 26 Dec 2008 15:11:37 +0000 Subject: [PATCH] finish fast enumeration conversion --- macosx/GroupsController.m | 16 ++++------------ macosx/InfoWindowController.m | 31 ++++++++----------------------- macosx/Torrent.m | 2 +- macosx/TorrentTableView.m | 12 +++--------- 4 files changed, 16 insertions(+), 45 deletions(-) diff --git a/macosx/GroupsController.m b/macosx/GroupsController.m index aa7151e30..6727227d5 100644 --- a/macosx/GroupsController.m +++ b/macosx/GroupsController.m @@ -255,9 +255,7 @@ GroupsController * fGroupsInstance = nil; for (index = 0; index < [fGroups count]; index++) { BOOL found = NO; - NSEnumerator * enumerator = [fGroups objectEnumerator]; - NSDictionary * dict; - while ((dict = [enumerator nextObject])) + for (NSDictionary * dict in fGroups) if ([[dict objectForKey: @"Index"] intValue] == index) { found = YES; @@ -333,9 +331,7 @@ GroupsController * fGroupsInstance = nil; [menu addItem: item]; [item release]; - NSEnumerator * enumerator = [fGroups objectEnumerator]; - NSMutableDictionary * dict; - while ((dict = [enumerator nextObject])) + for (NSMutableDictionary * dict in fGroups) { item = [[NSMenuItem alloc] initWithTitle: [dict objectForKey: @"Name"] action: action keyEquivalent: @""]; [item setTarget: target]; @@ -364,9 +360,7 @@ GroupsController * fGroupsInstance = nil; - (NSInteger) groupIndexForTorrent: (Torrent *) torrent; { - NSEnumerator * enumerator = [fGroups objectEnumerator]; - NSMutableDictionary * group; - while ((group = [enumerator nextObject])) + for (NSDictionary * group in fGroups) { NSInteger row = [[group objectForKey: @"Index"] intValue]; if ([self torrent: torrent doesMatchRulesForGroupAtIndex: row]) @@ -383,9 +377,7 @@ GroupsController * fGroupsInstance = nil; { //don't archive the icon NSMutableArray * groups = [NSMutableArray arrayWithCapacity: [fGroups count]]; - NSEnumerator * enumerator = [fGroups objectEnumerator]; - NSDictionary * dict; - while ((dict = [enumerator nextObject])) + for (NSDictionary * dict in fGroups) { NSMutableDictionary * tempDict = [dict mutableCopy]; [tempDict removeObjectForKey: @"Icon"]; diff --git a/macosx/InfoWindowController.m b/macosx/InfoWindowController.m index 36fe5625f..90248dcb9 100644 --- a/macosx/InfoWindowController.m +++ b/macosx/InfoWindowController.m @@ -245,9 +245,7 @@ typedef enum uint64_t size = 0; NSInteger fileCount = 0; - NSEnumerator * enumerator = [torrents objectEnumerator]; - Torrent * torrent; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in torrents) { size += [torrent size]; fileCount += [torrent fileCount]; @@ -1202,9 +1200,7 @@ typedef enum return; } - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) [torrent setSpeedMode: mode upload: upload]; NSTextField * field = upload ? fUploadLimitField : fDownloadLimitField; @@ -1226,10 +1222,7 @@ typedef enum BOOL upload = sender == fUploadLimitField; NSInteger limit = [sender intValue]; - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) [torrent setSpeedLimit: limit upload: upload]; } @@ -1251,9 +1244,7 @@ typedef enum return; } - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) [torrent setRatioSetting: setting]; BOOL single = setting == NSOnState; @@ -1271,9 +1262,7 @@ typedef enum { CGFloat limit = [sender floatValue]; - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) [torrent setRatioLimit: limit]; } @@ -1281,9 +1270,7 @@ typedef enum { NSInteger limit = [sender intValue]; - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) [torrent setMaxPeerConnect: limit]; } @@ -1334,9 +1321,7 @@ typedef enum uint64_t have = 0, haveVerified = 0, downloadedTotal = 0, uploadedTotal = 0, failedHash = 0; NSDate * lastActivity = nil; - Torrent * torrent; - NSEnumerator * enumerator = [fTorrents objectEnumerator]; - while ((torrent = [enumerator nextObject])) + for (Torrent * torrent in fTorrents) { have += [torrent haveTotal]; haveVerified += [torrent haveVerified]; @@ -1369,7 +1354,7 @@ typedef enum if (numberSelected == 1) { - torrent = [fTorrents objectAtIndex: 0]; + Torrent * torrent = [fTorrents objectAtIndex: 0]; [fStateField setStringValue: [torrent stateString]]; diff --git a/macosx/Torrent.m b/macosx/Torrent.m index ae1ca40b0..8521e70f3 100644 --- a/macosx/Torrent.m +++ b/macosx/Torrent.m @@ -1744,7 +1744,7 @@ int trashDataFile(const char * filename) if ([pathComponents count] > 0) { //determine if folder node already exists - FileListNode * node = nil; + FileListNode * node; for (node in fileList) if ([[node name] isEqualToString: name] && [node isFolder]) break; diff --git a/macosx/TorrentTableView.m b/macosx/TorrentTableView.m index 7b40fcbc8..0b9e7a7be 100644 --- a/macosx/TorrentTableView.m +++ b/macosx/TorrentTableView.m @@ -245,9 +245,7 @@ fMouseRevealRow = -1; fMouseActionRow = -1; - 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]; @@ -402,9 +400,7 @@ { NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet]; - NSEnumerator * enumerator = [values objectEnumerator]; - id item; - while ((item = [enumerator nextObject])) + for (id item in values) { if ([item isKindOfClass: [Torrent class]]) { @@ -881,9 +877,7 @@ - (void) createFileMenu: (NSMenu *) menu forFiles: (NSArray *) files { - NSEnumerator * enumerator = [files objectEnumerator]; - FileListNode * node; - while ((node = [enumerator nextObject])) + for (FileListNode * node in files) { NSString * name = [node name];