Changeset 7505


Ignore:
Timestamp:
Dec 26, 2008, 12:16:19 AM (12 years ago)
Author:
livings124
Message:

reuse existing TorrentGroup? object instead of recreating constantly (fixes #1415)

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r7468 r7505  
    21142114    if (groupRows)
    21152115    {
     2116        NSArray * oldTorrentGroups = nil;
     2117        if ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])
     2118            oldTorrentGroups = [NSArray arrayWithArray: fDisplayedTorrents];
     2119       
    21162120        [fDisplayedTorrents removeAllObjects];
    21172121       
     
    21202124       
    21212125        NSMutableArray * groupTorrents;
    2122         for (NSInteger i = 0, oldGroupValue = -2; i < [allTorrents count]; i++)
    2123         {
    2124             torrent = [allTorrents objectAtIndex: i];
     2126        NSInteger lastGroupValue = -2, currentOldGroupIndex = 0;
     2127        NSEnumerator * enumerator = [allTorrents objectEnumerator];
     2128        while ((torrent = [enumerator nextObject]))
     2129        {
    21252130            NSInteger groupValue = [torrent groupValue];
    2126             if (groupValue != oldGroupValue)
     2131            if (groupValue != lastGroupValue)
    21272132            {
    2128                 TorrentGroup * group = [[TorrentGroup alloc] initWithGroup: groupValue];
     2133                TorrentGroup * group = nil;
     2134               
     2135                //try to see if the group already exists
     2136                for (; oldTorrentGroups && currentOldGroupIndex < [oldTorrentGroups count]; currentOldGroupIndex++)
     2137                {
     2138                    TorrentGroup * currentGroup = [oldTorrentGroups objectAtIndex: currentOldGroupIndex];
     2139                    if ([currentGroup groupIndex] == groupValue)
     2140                    {
     2141                        group = currentGroup;
     2142                        [[currentGroup torrents] removeAllObjects];
     2143                        break;
     2144                    }
     2145                }
     2146               
     2147                if (!group)
     2148                    group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
     2149                [fDisplayedTorrents addObject: group];
     2150               
    21292151                groupTorrents = [group torrents];
    21302152               
    2131                 [fDisplayedTorrents addObject: group];
    2132                 [group release];
    2133                
    2134                 oldGroupValue = groupValue;
     2153                lastGroupValue = groupValue;
    21352154            }
    21362155           
  • trunk/macosx/NSStringAdditions.m

    r7032 r7505  
    148148- (NSComparisonResult) compareFinder: (NSString *) string
    149149{
    150     NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch
    151                                                             | NSWidthInsensitiveSearch | NSForcedOrderingSearch)
    152                                                         : (NSCaseInsensitiveSearch | NSNumericSearch);
     150    const NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter]
     151                                ? (NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch)
     152                                : (NSCaseInsensitiveSearch | NSNumericSearch);
    153153    return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
    154154}
     
    156156- (NSComparisonResult) compareNumeric: (NSString *) string
    157157{
    158     NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch;
     158    const NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch;
    159159    return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
    160160}
Note: See TracChangeset for help on using the changeset viewer.