Changeset 7513


Ignore:
Timestamp:
Dec 26, 2008, 7:06:02 AM (12 years ago)
Author:
livings124
Message:

switch over Controller.m's enumerator's to Objective-C 2's fast enumeration

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r7508 r7513  
    164164    int processIdentifier = [[NSProcessInfo processInfo] processIdentifier];
    165165
    166     NSDictionary * dic;
    167     NSEnumerator * enumerator = [[[NSWorkspace sharedWorkspace] launchedApplications] objectEnumerator];
    168     while ((dic = [enumerator nextObject]))
     166    for (NSDictionary * dic in [[NSWorkspace sharedWorkspace] launchedApplications])
    169167    {
    170168        if ([[dic objectForKey: @"NSApplicationBundleIdentifier"] isEqualToString: bundleIdentifier]
     
    368366    if (history)
    369367    {
    370         Torrent * torrent;
    371         NSDictionary * historyItem;
    372         NSEnumerator * enumerator = [history objectEnumerator];
    373         while ((historyItem = [enumerator nextObject]))
     368        for (NSDictionary * historyItem in history)
     369        {
     370            Torrent * torrent;
    374371            if ((torrent = [[Torrent alloc] initWithHistory: historyItem lib: fLib]))
    375372            {
     
    377374                [torrent release];
    378375            }
    379        
     376        }
    380377        [history release];
    381378    }
     
    520517    {
    521518        NSInteger active = 0, downloading = 0;
    522         Torrent * torrent;
    523         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    524         while ((torrent = [enumerator nextObject]))
     519        for (Torrent * torrent  in fTorrents)
    525520            if ([torrent isActive] && ![torrent isStalled])
    526521            {
     
    581576    if (fPendingTorrentDownloads)
    582577    {
    583         NSEnumerator * downloadEnumerator = [fPendingTorrentDownloads objectEnumerator];
    584         NSDictionary * downloadDict;
    585         while ((downloadDict = [downloadEnumerator nextObject]))
     578        for (NSDictionary * downloadDict in fPendingTorrentDownloads)
    586579        {
    587580            NSURLDownload * download = [downloadDict objectForKey: @"Download"];
     
    768761    }
    769762   
    770     Torrent * torrent;
    771     NSString * torrentPath;
    772763    tr_info info;
    773     NSEnumerator * enumerator = [filenames objectEnumerator];
    774     while ((torrentPath = [enumerator nextObject]))
     764    for (NSString * torrentPath in filenames)
    775765    {
    776766        //ensure torrent doesn't already exist
     
    818808        tr_metainfoFree(&info);
    819809       
     810        Torrent * torrent;
    820811        if (!(torrent = [[Torrent alloc] initWithPath: torrentPath location: location
    821812                            deleteTorrentFile: showWindow ? TORRENT_FILE_SAVE : deleteTorrentFile lib: fLib]))
     
    10721063- (void) resumeTorrents: (NSArray *) torrents
    10731064{
    1074     NSEnumerator * enumerator = [torrents objectEnumerator];
    1075     Torrent * torrent;
    1076     while ((torrent = [enumerator nextObject]))
     1065    for (Torrent * torrent in torrents)
    10771066        [torrent setWaitToStart: YES];
    10781067   
     
    10891078    NSMutableArray * torrents = [NSMutableArray arrayWithCapacity: [fTorrents count]];
    10901079   
    1091     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1092     Torrent * torrent;
    1093     while ((torrent = [enumerator nextObject]))
     1080    for (Torrent * torrent in fTorrents)
    10941081        if (![torrent isActive] && [torrent waitingToStart])
    10951082            [torrents addObject: torrent];
     
    11011088{
    11021089    //iterate through instead of all at once to ensure no conflicts
    1103     NSEnumerator * enumerator = [torrents objectEnumerator];
    1104     Torrent * torrent;
    1105     while ((torrent = [enumerator nextObject]))
     1090    for (Torrent * torrent in torrents)
    11061091        [torrent startTransfer];
    11071092   
     
    11241109{
    11251110    //don't want any of these starting then stopping
    1126     NSEnumerator * enumerator = [torrents objectEnumerator];
    1127     Torrent * torrent;
    1128     while ((torrent = [enumerator nextObject]))
     1111    for (Torrent * torrent in torrents)
    11291112        [torrent setWaitToStart: NO];
    11301113
     
    11431126    if ([fDefaults boolForKey: @"CheckRemove"])
    11441127    {
    1145         Torrent * torrent;
    1146         NSEnumerator * enumerator = [torrents objectEnumerator];
    1147         while ((torrent = [enumerator nextObject]))
     1128        for (Torrent * torrent in torrents)
    11481129            if ([torrent isActive])
    11491130            {
     
    12431224{
    12441225    //don't want any of these starting then stopping
    1245     NSEnumerator * enumerator = [torrents objectEnumerator];
    1246     Torrent * torrent;
    1247     while ((torrent = [enumerator nextObject]))
     1226    for (Torrent * torrent in torrents)
    12481227        [torrent setWaitToStart: NO];
    12491228   
     
    12511230   
    12521231    NSInteger lowestOrderValue = NSIntegerMax;
    1253     enumerator = [torrents objectEnumerator];
    1254     while ((torrent = [enumerator nextObject]))
     1232    for (Torrent * torrent in torrents)
    12551233    {
    12561234        //let's expand all groups that have removed items - they either don't exist anymore, are already expanded, or are collapsed (rpc)
     
    13321310    if (code == NSOKButton)
    13331311    {
    1334         NSEnumerator * enumerator = [torrents objectEnumerator];
    1335         Torrent * torrent;
    1336         while ((torrent = [enumerator nextObject]))
     1312        for (Torrent * torrent in torrents)
    13371313            [torrent moveTorrentDataFileTo: [[panel filenames] objectAtIndex: 0]];
    13381314    }
     
    13971373- (void) revealFile: (id) sender
    13981374{
    1399     NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    1400     Torrent * torrent;
    1401     while ((torrent = [enumerator nextObject]))
     1375    for (Torrent * torrent in [fTableView selectedTorrents])
    14021376        [torrent revealData];
    14031377}
     
    14051379- (void) announceSelectedTorrents: (id) sender
    14061380{
    1407     NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    1408     Torrent * torrent;
    1409     while ((torrent = [enumerator nextObject]))
     1381    for (Torrent * torrent in [fTableView selectedTorrents])
    14101382    {
    14111383        if ([torrent canManualAnnounce])
     
    14211393- (void) verifyTorrents: (NSArray *) torrents
    14221394{
    1423     NSEnumerator * enumerator = [torrents objectEnumerator];
    1424     Torrent * torrent;
    1425     while ((torrent = [enumerator nextObject]))
     1395    for (Torrent * torrent in torrents)
    14261396        [torrent resetCache];
    14271397   
     
    16191589        desiredSeedActive = [self numToStartFromQueue: NO];
    16201590   
    1621     Torrent * torrent;
    1622     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1623     while ((torrent = [enumerator nextObject]))
     1591    for (Torrent * torrent in fTorrents)
    16241592    {
    16251593        if (![torrent isActive] && ![torrent isChecking] && [torrent waitingToStart])
     
    16601628    NSInteger desired = [fDefaults integerForKey: downloadQueue ? @"QueueDownloadNumber" : @"QueueSeedNumber"];
    16611629       
    1662     Torrent * torrent;
    1663     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1664     while ((torrent = [enumerator nextObject]))
     1630    for (Torrent * torrent in fTorrents)
    16651631    {
    16661632        if ([torrent isChecking])
     
    17701736    NSMutableArray * history = [NSMutableArray arrayWithCapacity: [fTorrents count]];
    17711737
    1772     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1773     Torrent * torrent;
    1774     while ((torrent = [enumerator nextObject]))
     1738    for (Torrent * torrent in fTorrents)
    17751739        [history addObject: [torrent history]];
    17761740
     
    19071871    if ([fDefaults boolForKey: @"SortByGroup"])
    19081872    {
    1909         NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator];
    1910         TorrentGroup * group;
    1911         while ((group = [enumerator nextObject]))
     1873        for (TorrentGroup * group in fDisplayedTorrents)
    19121874            [[group torrents] sortUsingDescriptors: descriptors];
    19131875    }
     
    19281890        previousTorrents = [NSMutableArray array];
    19291891       
    1930         NSEnumerator * enumerator = [fDisplayedTorrents objectEnumerator];
    1931         TorrentGroup * group;
    1932         while ((group = [enumerator nextObject]))
     1892        for (TorrentGroup * group in fDisplayedTorrents)
    19331893            [previousTorrents addObjectsFromArray: [group torrents]];
    19341894    }
     
    19621922   
    19631923    //get count of each type
    1964     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    1965     Torrent * torrent;
    19661924    NSInteger index = -1;
    1967     while ((torrent = [enumerator nextObject]))
     1925    for (Torrent * torrent in fTorrents)
    19681926    {
    19691927        index++;
     
    20111969            {
    20121970                BOOL removeTextField = YES;
    2013                 NSEnumerator * trackerEnumerator = [[torrent allTrackers: NO] objectEnumerator];
    2014                 NSString * tracker;
    2015                 while ((tracker = [trackerEnumerator nextObject]))
     1971                for (NSString * tracker in [torrent allTrackers: NO])
    20161972                {
    20171973                    if ([tracker rangeOfString: searchString options: NSCaseInsensitiveSearch].location != NSNotFound)
     
    20462002    //clear display cache for not-shown torrents
    20472003    [previousTorrents removeObjectsInArray: allTorrents];
    2048     enumerator = [previousTorrents objectEnumerator];
    2049     while ((torrent = [enumerator nextObject]))
     2004    for (Torrent * torrent in previousTorrents)
    20502005        [torrent setPreviousFinishedPieces: nil];
    20512006   
     
    20652020        NSMutableArray * groupTorrents;
    20662021        NSInteger lastGroupValue = -2, currentOldGroupIndex = 0;
    2067         NSEnumerator * enumerator = [allTorrents objectEnumerator];
    2068         while ((torrent = [enumerator nextObject]))
     2022        for (Torrent * torrent in allTorrents)
    20692023        {
    20702024            NSInteger groupValue = [torrent groupValue];
     
    21062060    if (groupRows)
    21072061    {
    2108         enumerator = [fDisplayedTorrents objectEnumerator];
    2109         TorrentGroup * group;
    2110         while ((group = [enumerator nextObject]))
     2062        for (TorrentGroup * group in fDisplayedTorrents)
    21112063        {
    21122064            if ([fTableView isGroupCollapsed: [group groupIndex]])
     
    23082260- (void) setGroup: (id) sender
    23092261{
    2310     NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    2311     Torrent * torrent;
    2312     while ((torrent = [enumerator nextObject]))
     2262    for (Torrent * torrent in [fTableView selectedTorrents])
    23132263    {
    23142264        [fTableView removeCollapsedGroup: [torrent groupValue]]; //remove old collapsed group
     
    25522502    [fAutoImportedNames setArray: importedNames];
    25532503   
    2554     NSString * file;
    25552504    for (NSInteger i = [newNames count] - 1; i >= 0; i--)
    25562505    {
    2557         file = [newNames objectAtIndex: i];
     2506        NSString * file = [newNames objectAtIndex: i];
    25582507        if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] != NSOrderedSame)
    25592508            [newNames removeObjectAtIndex: i];
     
    25622511    }
    25632512   
    2564     NSEnumerator * enumerator = [newNames objectEnumerator];
    2565     tr_ctor * ctor;
    2566     while ((file = [enumerator nextObject]))
    2567     {
    2568         ctor = tr_ctorNew(fLib);
     2513    for (NSString * file in newNames)
     2514    {
     2515        tr_ctor * ctor = tr_ctorNew(fLib);
    25692516        tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    25702517       
     
    26672614    {
    26682615        NSMutableIndexSet * indexSet = [NSMutableIndexSet indexSet];
    2669         NSEnumerator * enumerator = [items objectEnumerator];
    2670         id torrent;
    2671         while ((torrent = [enumerator nextObject]))
     2616        for (id torrent in items)
    26722617        {
    26732618            if (![torrent isKindOfClass: [Torrent class]])
     
    27482693            //change groups
    27492694            NSInteger groupValue = [item groupIndex];
    2750             NSEnumerator * enumerator = [movingTorrents objectEnumerator];
    2751             Torrent * torrent;
    2752             while ((torrent = [enumerator nextObject]))
     2695            for (Torrent * torrent in movingTorrents)
    27532696            {
    27542697                //have to reset objects here to avoid weird crash
     
    28092752    {
    28102753        //check if any torrent files can be added
     2754        BOOL torrent = NO;
    28112755        NSArray * files = [pasteboard propertyListForType: NSFilenamesPboardType];
    2812         NSEnumerator * enumerator = [files objectEnumerator];
    2813         NSString * file;
    2814         BOOL torrent = NO;
    2815         tr_ctor * ctor;
    2816         while ((file = [enumerator nextObject]))
     2756        for (NSString * file in files)
    28172757        {
    28182758            if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
    28192759            {
    2820                 ctor = tr_ctorNew(fLib);
     2760                tr_ctor * ctor = tr_ctorNew(fLib);
    28212761                tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    28222762                switch (tr_torrentParse(fLib, ctor, NULL))
     
    28782818        NSMutableArray * filesToOpen = [[NSMutableArray alloc] init];
    28792819        NSArray * files = [pasteboard propertyListForType: NSFilenamesPboardType];
    2880         NSEnumerator * enumerator = [files objectEnumerator];
    2881         NSString * file;
    2882         tr_ctor * ctor;
    2883         while ((file = [enumerator nextObject]))
     2820        for (NSString * file in files)
    28842821        {
    28852822            if ([[file pathExtension] caseInsensitiveCompare: @"torrent"] == NSOrderedSame)
    28862823            {
    2887                 ctor = tr_ctorNew(fLib);
     2824                tr_ctor * ctor = tr_ctorNew(fLib);
    28882825                tr_ctorSetMetainfoFromFile(ctor, [file UTF8String]);
    28892826                switch (tr_torrentParse(fLib, ctor, NULL))
     
    34143351    if ([ident isEqualToString: TOOLBAR_PAUSE_ALL])
    34153352    {
    3416         Torrent * torrent;
    3417         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3418         while ((torrent = [enumerator nextObject]))
     3353        for (Torrent * torrent in fTorrents)
    34193354            if ([torrent isActive] || [torrent waitingToStart])
    34203355                return YES;
     
    34253360    if ([ident isEqualToString: TOOLBAR_RESUME_ALL])
    34263361    {
    3427         Torrent * torrent;
    3428         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3429         while ((torrent = [enumerator nextObject]))
     3362        for (Torrent * torrent in fTorrents)
    34303363            if (![torrent isActive] && ![torrent waitingToStart])
    34313364                return YES;
     
    34363369    if ([ident isEqualToString: TOOLBAR_PAUSE_SELECTED])
    34373370    {
    3438         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3439         Torrent * torrent;
    3440         while ((torrent = [enumerator nextObject]))
     3371        for (Torrent * torrent in [fTableView selectedTorrents])
    34413372            if ([torrent isActive] || [torrent waitingToStart])
    34423373                return YES;
     
    34473378    if ([ident isEqualToString: TOOLBAR_RESUME_SELECTED])
    34483379    {
    3449         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3450         Torrent * torrent;
    3451         while ((torrent = [enumerator nextObject]))
     3380        for (Torrent * torrent in [fTableView selectedTorrents])
    34523381            if (![torrent isActive] && ![torrent waitingToStart])
    34533382                return YES;
     
    35543483       
    35553484        NSInteger index = [menuItem tag];
    3556         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3557         Torrent * torrent;
    3558         while ((torrent = [enumerator nextObject]))
     3485        for (Torrent * torrent in [fTableView selectedTorrents])
    35593486            if (index == [torrent groupValue])
    35603487            {
     
    36853612            canDelete = action != @selector(removeDeleteTorrent:) && action != @selector(removeDeleteDataAndTorrent:);
    36863613       
    3687         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3688         Torrent * torrent;
    3689         while ((torrent = [enumerator nextObject]))
     3614        for (Torrent * torrent in [fTableView selectedTorrents])
    36903615        {
    36913616            if (!warning && [torrent isActive])
     
    37223647    if (action == @selector(stopAllTorrents:))
    37233648    {
    3724         Torrent * torrent;
    3725         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3726         while ((torrent = [enumerator nextObject]))
     3649        for (Torrent * torrent in fTorrents)
    37273650            if ([torrent isActive] || [torrent waitingToStart])
    37283651                return YES;
     
    37333656    if (action == @selector(resumeAllTorrents:))
    37343657    {
    3735         Torrent * torrent;
    3736         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3737         while ((torrent = [enumerator nextObject]))
     3658        for (Torrent * torrent in fTorrents)
    37383659            if (![torrent isActive] && ![torrent waitingToStart])
    37393660                return YES;
     
    37473668            return NO;
    37483669   
    3749         Torrent * torrent;
    3750         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3751         while ((torrent = [enumerator nextObject]))
     3670        for (Torrent * torrent in fTorrents)
    37523671            if (![torrent isActive] && [torrent waitingToStart])
    37533672                return YES;
     
    37613680            return NO;
    37623681       
    3763         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3764         Torrent * torrent;
    3765         while ((torrent = [enumerator nextObject]))
     3682        for (Torrent * torrent in [fTableView selectedTorrents])
    37663683            if (![torrent isActive])
    37673684                return YES;
     
    37753692            return NO;
    37763693   
    3777         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3778         Torrent * torrent;
    3779         while ((torrent = [enumerator nextObject]))
     3694        for (Torrent * torrent in [fTableView selectedTorrents])
    37803695            if ([torrent isActive] || [torrent waitingToStart])
    37813696                return YES;
     
    37893704            return NO;
    37903705   
    3791         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3792         Torrent * torrent;
    3793         while ((torrent = [enumerator nextObject]))
     3706        for (Torrent * torrent in [fTableView selectedTorrents])
    37943707            if (![torrent isActive] && ![torrent waitingToStart])
    37953708                return YES;
     
    38033716            return NO;
    38043717       
    3805         NSEnumerator * enumerator = [[fTableView selectedTorrents] objectEnumerator];
    3806         Torrent * torrent;
    3807         while ((torrent = [enumerator nextObject]))
     3718        for (Torrent * torrent in [fTableView selectedTorrents])
    38083719            if ([torrent canManualAnnounce])
    38093720                return YES;
     
    38573768- (void) sleepCallback: (natural_t) messageType argument: (void *) messageArgument
    38583769{
    3859     NSEnumerator * enumerator;
    3860     Torrent * torrent;
    3861 
    38623770    switch (messageType)
    38633771    {
    38643772        case kIOMessageSystemWillSleep:
    38653773            //if there are any running transfers, wait 15 seconds for them to stop
    3866             enumerator = [fTorrents objectEnumerator];
    3867             while ((torrent = [enumerator nextObject]))
     3774            for (Torrent * torrent in fTorrents)
    38683775                if ([torrent isActive])
    38693776                {
     
    38813788            {
    38823789                //prevent idle sleep unless no torrents are active
    3883                 enumerator = [fTorrents objectEnumerator];
    3884                 while ((torrent = [enumerator nextObject]))
     3790                for (Torrent * torrent in fTorrents)
    38853791                    if ([torrent isActive] && ![torrent isStalled] && ![torrent isError])
    38863792                    {
     
    39043810{
    39053811    NSInteger seeding = 0, downloading = 0;
    3906     NSEnumerator * enumerator = [fTorrents objectEnumerator];
    3907     Torrent * torrent;
    3908     while ((torrent = [enumerator nextObject]))
     3812    for (Torrent * torrent in fTorrents)
    39093813    {
    39103814        if ([torrent isSeeding])
     
    41124016    NSArray * selectedTorrents = [fTableView selectedTorrents];
    41134017    NSMutableArray * urlArray = [NSMutableArray arrayWithCapacity: [selectedTorrents count]];
    4114     NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
    4115     Torrent * torrent;
    4116    
    4117     while ((torrent = [enumerator nextObject]))
     4018   
     4019    for (Torrent * torrent in selectedTorrents)
    41184020        if ([self canQuickLookTorrent: torrent])
    41194021            [urlArray addObject: [NSURL fileURLWithPath: [torrent dataLocation]]];
     
    41244026- (BOOL) canQuickLook
    41254027{
    4126     NSArray * selectedTorrents = [fTableView selectedTorrents];
    4127     NSEnumerator * enumerator = [selectedTorrents objectEnumerator];
    4128     Torrent * torrent;
    4129    
    4130     while ((torrent = [enumerator nextObject]))
     4028    for (Torrent * torrent in [fTableView selectedTorrents])
    41314029        if ([self canQuickLookTorrent: torrent])
    41324030            return YES;
     
    42244122    if (torrentStruct != NULL && (type != TR_RPC_TORRENT_ADDED && type != TR_RPC_SESSION_CHANGED))
    42254123    {
    4226         NSEnumerator * enumerator = [fTorrents objectEnumerator];
    4227         while ((torrent = [enumerator nextObject]))
     4124        for (torrent in fTorrents)
    42284125            if (torrentStruct == [torrent torrentStruct])
    42294126            {
Note: See TracChangeset for help on using the changeset viewer.