From b15e4f626a21fce9c15c7b9ea26435e11f378176 Mon Sep 17 00:00:00 2001 From: vspader Date: Wed, 20 Feb 2008 00:54:45 +0000 Subject: [PATCH] Moved most enumerators to fast enumeration. --- Application/AppController.m | 4 +--- FileTreeWindow/ContainerNode.m | 4 +--- FileTreeWindow/DirectoryNode.m | 5 ++--- FileTreeWindow/FileTreeDataSource.m | 4 +--- FileTreeWindow/PathNode.m | 4 +--- Playlist/DNDArrayController.h | 1 - Playlist/DNDArrayController.m | 5 ++--- Playlist/PlaylistController.m | 13 +++---------- Playlist/PlaylistHeaderView.m | 4 +--- Playlist/PlaylistLoader.m | 28 ++++++++-------------------- TODO | 2 +- 11 files changed, 21 insertions(+), 53 deletions(-) diff --git a/Application/AppController.m b/Application/AppController.m index 39d16536b..8137648a8 100644 --- a/Application/AppController.m +++ b/Application/AppController.m @@ -311,10 +311,8 @@ increase/decrease as long as the user holds the left/right, plus/minus button */ { //Need to convert to urls NSMutableArray *urls = [NSMutableArray array]; - NSEnumerator *e = [filenames objectEnumerator]; - NSString *filename; - while (filename = [e nextObject]) + for (NSString *filename in filenames) { [urls addObject:[NSURL fileURLWithPath:filename]]; } diff --git a/FileTreeWindow/ContainerNode.m b/FileTreeWindow/ContainerNode.m index 8336d7662..e1f2cb294 100644 --- a/FileTreeWindow/ContainerNode.m +++ b/FileTreeWindow/ContainerNode.m @@ -22,10 +22,8 @@ { NSArray *urls = [AudioContainer urlsForContainerURL:url]; - NSURL *u; - NSEnumerator *e = [urls objectEnumerator]; NSMutableArray *paths = [[NSMutableArray alloc] init]; - while (u = [e nextObject]) + for (NSURL *u in urls) { ContainedNode *node = [[ContainedNode alloc] initWithDataSource:dataSource url:u]; NSLog(@"Node: %@", u); diff --git a/FileTreeWindow/DirectoryNode.m b/FileTreeWindow/DirectoryNode.m index 06a85a9ca..b16cf5e5f 100644 --- a/FileTreeWindow/DirectoryNode.m +++ b/FileTreeWindow/DirectoryNode.m @@ -22,9 +22,8 @@ { NSArray *contents = [[[NSFileManager defaultManager] directoryContentsAtPath:[url path]] sortedArrayUsingSelector:@selector(caseInsensitiveCompare:)]; NSMutableArray *fullPaths = [[NSMutableArray alloc] init]; - NSString *s; - NSEnumerator *e = [contents objectEnumerator]; - while (s = [e nextObject]) + + for (NSString *s in contents) { [fullPaths addObject:[[url path] stringByAppendingPathComponent: s]]; } diff --git a/FileTreeWindow/FileTreeDataSource.m b/FileTreeWindow/FileTreeDataSource.m index d5c91a1fa..af156d4e1 100644 --- a/FileTreeWindow/FileTreeDataSource.m +++ b/FileTreeWindow/FileTreeDataSource.m @@ -130,10 +130,8 @@ - (BOOL)outlineView:(NSOutlineView *)outlineView writeItems:(NSArray*)items toPasteboard:(NSPasteboard*)pboard { //Get selected paths NSMutableArray *urls = [NSMutableArray arrayWithCapacity:[items count]]; - NSEnumerator *e = [items objectEnumerator]; - id p; - while (p = [e nextObject]) { + for (id p in items) { [urls addObject:[p url]]; } NSLog(@"URLS: %@", urls); diff --git a/FileTreeWindow/PathNode.m b/FileTreeWindow/PathNode.m index 4b216051e..8da8e4838 100644 --- a/FileTreeWindow/PathNode.m +++ b/FileTreeWindow/PathNode.m @@ -89,9 +89,7 @@ NSURL *resolveAliases(NSURL *url) { NSMutableArray *newSubpaths = [[NSMutableArray alloc] init]; - NSEnumerator *e = [contents objectEnumerator]; - NSString *s; - while ((s = [e nextObject])) + for (NSString *s in contents) { if ([s characterAtIndex:0] == '.') { diff --git a/Playlist/DNDArrayController.h b/Playlist/DNDArrayController.h index 6d1d957cd..f6f9adfe3 100755 --- a/Playlist/DNDArrayController.h +++ b/Playlist/DNDArrayController.h @@ -22,6 +22,5 @@ extern NSString *iTunesDropType; -(void)moveObjectsInArrangedObjectsFromIndexes:(NSIndexSet*)indexSet toIndex:(unsigned int)insertIndex; - (NSIndexSet *)indexSetFromRows:(NSArray *)rows; -- (int)rowsAboveRow:(int)row inIndexSet:(NSIndexSet *)indexSet; @end diff --git a/Playlist/DNDArrayController.m b/Playlist/DNDArrayController.m index cc5191faf..b86874cf6 100755 --- a/Playlist/DNDArrayController.m +++ b/Playlist/DNDArrayController.m @@ -138,9 +138,8 @@ NSString *iTunesDropType = @"CorePasteboardFlavorType 0x6974756E"; - (NSIndexSet *)indexSetFromRows:(NSArray *)rows { NSMutableIndexSet *indexSet = [NSMutableIndexSet indexSet]; - NSEnumerator *rowEnumerator = [rows objectEnumerator]; - NSNumber *idx; - while (idx = [rowEnumerator nextObject]) + + for (NSNumber *idx in rows) { [indexSet addIndex:[idx unsignedIntValue]]; } diff --git a/Playlist/PlaylistController.m b/Playlist/PlaylistController.m index 13b04b05d..f21c57d55 100644 --- a/Playlist/PlaylistController.m +++ b/Playlist/PlaylistController.m @@ -122,9 +122,7 @@ if ([bestType isEqualToString:NSFilenamesPboardType]) { NSMutableArray *urls = [[NSMutableArray alloc] init]; - NSEnumerator *e = [[[info draggingPasteboard] propertyListForType:NSFilenamesPboardType] objectEnumerator]; - NSString *file; - while (file = [e nextObject]) + for (NSString *file in [[info draggingPasteboard] propertyListForType:NSFilenamesPboardType]) { [urls addObject:[NSURL fileURLWithPath:file]]; } @@ -142,9 +140,7 @@ // Convert the iTunes URLs to URLs....MWAHAHAH! NSMutableArray *urls = [[NSMutableArray alloc] init]; - NSEnumerator *e = [[tracks allValues] objectEnumerator]; - NSDictionary *trackInfo; - while (trackInfo = [e nextObject]) { + for (NSDictionary *trackInfo in [tracks allValues]) { [urls addObject:[NSURL URLWithString:[trackInfo valueForKey:@"Location"]]]; } @@ -166,10 +162,7 @@ double tt = 0; ldiv_t hoursAndMinutes; - NSEnumerator *enumerator = [[self arrangedObjects] objectEnumerator]; - PlaylistEntry* pe; - - while (pe = [enumerator nextObject]) { + for (PlaylistEntry *pe in [self arrangedObjects]) { tt += [[pe length] doubleValue]; } diff --git a/Playlist/PlaylistHeaderView.m b/Playlist/PlaylistHeaderView.m index 0fe9eb161..04ec491b6 100644 --- a/Playlist/PlaylistHeaderView.m +++ b/Playlist/PlaylistHeaderView.m @@ -44,9 +44,7 @@ //find the longest string display length in that column float max_width = -1; - id row; - NSEnumerator *enumerator = [boundArray objectEnumerator]; - while (row = [enumerator nextObject]) { + for (id row in boundArray) { [cell setObjectValue:row]; diff --git a/Playlist/PlaylistLoader.m b/Playlist/PlaylistLoader.m index 3aac27a8a..6735d4aea 100755 --- a/Playlist/PlaylistLoader.m +++ b/Playlist/PlaylistLoader.m @@ -76,10 +76,7 @@ } [fileHandle truncateFileAtOffset:0]; - PlaylistEntry *pe; - NSEnumerator *e = [[playlistController content] objectEnumerator]; - - while (pe = [e nextObject]) + for (PlaylistEntry *pe in [playlistController content]) { NSString *path = [self relativePathFrom:filename toURL:[pe URL]]; [fileHandle writeData:[[path stringByAppendingString:@"\n"] dataUsingEncoding:NSUTF8StringEncoding]]; @@ -100,10 +97,8 @@ [fileHandle writeData:[[NSString stringWithFormat:@"[playlist]\nnumberOfEntries=%i\n\n",[[playlistController content] count]] dataUsingEncoding:NSUTF8StringEncoding]]; - NSEnumerator *e = [[playlistController content] objectEnumerator]; - PlaylistEntry *pe; int i = 1; - while (pe = [e nextObject]) + for (PlaylistEntry *pe in [playlistController content]) { NSString *path = [self relativePathFrom:filename toURL:[pe URL]]; NSString *entry = [NSString stringWithFormat:@"File%i=%@\n",i,path]; @@ -124,11 +119,9 @@ NSMutableArray *urls = [NSMutableArray array]; - NSString *subpath; NSArray *subpaths = [manager subpathsAtPath:path]; - NSEnumerator *e = [subpaths objectEnumerator]; - while(subpath = [e nextObject]) + for(NSString *subpath in subpaths) { NSString *absoluteSubpath = [NSString pathWithComponents:[NSArray arrayWithObjects:path,subpath,nil]]; @@ -157,9 +150,8 @@ if (index < 0) index = 0; - NSEnumerator *urlEnumerator = [urls objectEnumerator]; NSURL *url; - while (url = [urlEnumerator nextObject]) + for (url in urls) { if ([url isFileURL]) { BOOL isDir; @@ -199,8 +191,7 @@ sortedURLs = [expandedURLs copy]; } - urlEnumerator = [sortedURLs objectEnumerator]; - while (url = [urlEnumerator nextObject]) + for (url in sortedURLs) { //Container vs non-container url if ([[self acceptableContainerTypes] containsObject:[[[url path] pathExtension] lowercaseString]]) { @@ -219,8 +210,7 @@ NSLog(@"Contained urls: %@", containedURLs); - urlEnumerator = [fileURLs objectEnumerator]; - while (url = [urlEnumerator nextObject]) + for (url in fileURLs) { if (![[AudioPlayer schemes] containsObject:[url scheme]]) continue; @@ -239,8 +229,7 @@ NSLog(@"Valid urls: %@", validURLs); - urlEnumerator = [containedURLs objectEnumerator]; - while (url = [urlEnumerator nextObject]) + for (url in containedURLs) { if (![[AudioPlayer schemes] containsObject:[url scheme]]) continue; @@ -286,9 +275,8 @@ { NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - NSEnumerator *e = [entries objectEnumerator]; PlaylistEntry *pe; - while (pe = [e nextObject]) + for (pe in entries) { [pe readPropertiesThread]; diff --git a/TODO b/TODO index 8b1378917..fd340d97c 100644 --- a/TODO +++ b/TODO @@ -1 +1 @@ - +Get rid of negative index nonsense for removed playlist entry, instead just add a "removed" BOOL that gets set and can be checked. \ No newline at end of file