1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-24 16:52:39 +00:00

eliminate some more enumerator objects

This commit is contained in:
Mitchell Livingston 2008-12-26 07:25:17 +00:00
parent 8710f27709
commit f3add380e5
6 changed files with 19 additions and 41 deletions

View file

@ -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)
{

View file

@ -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];

View file

@ -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];

View file

@ -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]];

View file

@ -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]])
{

View file

@ -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;