1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 01:27:28 +00:00

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

This commit is contained in:
Mitchell Livingston 2008-12-26 00:16:19 +00:00
parent f5d3068746
commit e3b2d77ebf
2 changed files with 31 additions and 12 deletions

View file

@ -2113,25 +2113,44 @@ static void sleepCallback(void * controller, io_service_t y, natural_t messageTy
BOOL groupRows = [fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter]; BOOL groupRows = [fDefaults boolForKey: @"SortByGroup"] && [NSApp isOnLeopardOrBetter];
if (groupRows) if (groupRows)
{ {
NSArray * oldTorrentGroups = nil;
if ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])
oldTorrentGroups = [NSArray arrayWithArray: fDisplayedTorrents];
[fDisplayedTorrents removeAllObjects]; [fDisplayedTorrents removeAllObjects];
NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease]; NSSortDescriptor * groupDescriptor = [[[NSSortDescriptor alloc] initWithKey: @"groupOrderValue" ascending: YES] autorelease];
allTorrents = [allTorrents sortedArrayUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]]; allTorrents = [allTorrents sortedArrayUsingDescriptors: [NSArray arrayWithObject: groupDescriptor]];
NSMutableArray * groupTorrents; NSMutableArray * groupTorrents;
for (NSInteger i = 0, oldGroupValue = -2; i < [allTorrents count]; i++) NSInteger lastGroupValue = -2, currentOldGroupIndex = 0;
NSEnumerator * enumerator = [allTorrents objectEnumerator];
while ((torrent = [enumerator nextObject]))
{ {
torrent = [allTorrents objectAtIndex: i];
NSInteger groupValue = [torrent groupValue]; NSInteger groupValue = [torrent groupValue];
if (groupValue != oldGroupValue) if (groupValue != lastGroupValue)
{ {
TorrentGroup * group = [[TorrentGroup alloc] initWithGroup: groupValue]; TorrentGroup * group = nil;
//try to see if the group already exists
for (; oldTorrentGroups && currentOldGroupIndex < [oldTorrentGroups count]; currentOldGroupIndex++)
{
TorrentGroup * currentGroup = [oldTorrentGroups objectAtIndex: currentOldGroupIndex];
if ([currentGroup groupIndex] == groupValue)
{
group = currentGroup;
[[currentGroup torrents] removeAllObjects];
break;
}
}
if (!group)
group = [[[TorrentGroup alloc] initWithGroup: groupValue] autorelease];
[fDisplayedTorrents addObject: group];
groupTorrents = [group torrents]; groupTorrents = [group torrents];
[fDisplayedTorrents addObject: group]; lastGroupValue = groupValue;
[group release];
oldGroupValue = groupValue;
} }
[groupTorrents addObject: torrent]; [groupTorrents addObject: torrent];

View file

@ -147,15 +147,15 @@
- (NSComparisonResult) compareFinder: (NSString *) string - (NSComparisonResult) compareFinder: (NSString *) string
{ {
NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSCaseInsensitiveSearch | NSNumericSearch const NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter]
| NSWidthInsensitiveSearch | NSForcedOrderingSearch) ? (NSCaseInsensitiveSearch | NSNumericSearch | NSWidthInsensitiveSearch | NSForcedOrderingSearch)
: (NSCaseInsensitiveSearch | NSNumericSearch); : (NSCaseInsensitiveSearch | NSNumericSearch);
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]]; return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
} }
- (NSComparisonResult) compareNumeric: (NSString *) string - (NSComparisonResult) compareNumeric: (NSString *) string
{ {
NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch; const NSInteger comparisonOptions = [NSApp isOnLeopardOrBetter] ? (NSNumericSearch | NSForcedOrderingSearch) : NSNumericSearch;
return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]]; return [self compare: string options: comparisonOptions range: NSMakeRange(0, [self length]) locale: [NSLocale currentLocale]];
} }