Changeset 13131


Ignore:
Timestamp:
Jan 4, 2012, 11:40:23 PM (9 years ago)
Author:
livings124
Message:

speed up for #4696

Location:
trunk/macosx
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.h

    r13130 r13131  
    191191
    192192- (void) sortTorrents: (BOOL) includeQueueOrder;
    193 - (void) sortTorrentsIgnoreSelected: (NSMutableArray *) moves includeQueueOrder: (BOOL) includeQueueOrder;
    194 - (NSArray *) rearrangeTorrentArray: (NSMutableArray *) rearrangeArray to: (NSArray *) endingArray forParent: parent;
     193- (void) sortTorrentsIgnoreSelectedReloadTable: (BOOL) reload includeQueueOrder: (BOOL) includeQueueOrder;
     194- (void) rearrangeTorrentArray: (NSMutableArray *) rearrangeArray to: (NSArray *) endingArray forParent: parent beganTableUpdate: (BOOL *) beganTableUpdate;
    195195- (void) setSort: (id) sender;
    196196- (void) setSortByGroup: (id) sender;
  • trunk/macosx/Controller.m

    r13130 r13131  
    18331833- (void) sortTorrents: (BOOL) includeQueueOrder
    18341834{
     1835    const BOOL onLion = [NSApp isOnLionOrBetter];
     1836   
    18351837    NSArray * selectedValues;
    1836     if ([NSApp isOnLionOrBetter])
    1837         [fTableView beginUpdates];
    1838     else
     1838    if (!onLion)
    18391839        selectedValues = [fTableView selectedValues];
    18401840   
    1841     NSMutableArray * moves = [NSMutableArray array];
    1842     [self sortTorrentsIgnoreSelected: moves includeQueueOrder: includeQueueOrder]; //actually sort
    1843    
    1844     if ([NSApp isOnLionOrBetter])
    1845     {
    1846         for (NSDictionary * move in moves)
    1847         {
    1848             id parent = [move objectForKey: @"Parent"];
    1849             [fTableView moveItemAtIndex: [(NSNumber *)[move objectForKey: @"From"] unsignedIntegerValue] inParent: parent toIndex: [(NSNumber *)[move objectForKey: @"To"] unsignedIntegerValue] inParent: parent];
    1850         }
    1851        
    1852         [fTableView setNeedsDisplay: YES]; //need to make sure all have new info
    1853     }
    1854     else
    1855     {
    1856         if ([moves count] > 0)
    1857         {
    1858             [fTableView reloadData];
    1859             [fTableView selectValues: selectedValues];
    1860         }
    1861         else
    1862             [fTableView setNeedsDisplay: YES];
    1863     }
    1864    
    1865     if ([NSApp isOnLionOrBetter])
     1841    [self sortTorrentsIgnoreSelectedReloadTable: YES includeQueueOrder: includeQueueOrder]; //actually sort
     1842   
     1843    if (!onLion)
     1844        [fTableView selectValues: selectedValues];
     1845   
     1846    [fTableView setNeedsDisplay: YES];
     1847   
     1848    if (onLion)
    18661849        [fTableView endUpdates];
    18671850}
    18681851
    18691852#warning rename
    1870 - (void) sortTorrentsIgnoreSelected: (NSMutableArray *) moves includeQueueOrder: (BOOL) includeQueueOrder
    1871 {
    1872     [moves removeAllObjects];
    1873    
     1853- (void) sortTorrentsIgnoreSelectedReloadTable: (BOOL) reload includeQueueOrder: (BOOL) includeQueueOrder
     1854{
    18741855    //don't do anything else if we don't have to
    18751856    const BOOL sortByGroup = [fDefaults boolForKey: @"SortByGroup"];
     
    19431924    }
    19441925   
     1926    BOOL beganTableUpdate = NO;
     1927   
    19451928    //actually sort
    19461929    if (sortByGroup)
     
    19501933            if ([[group torrents] count] > 1)
    19511934            {
    1952                 if (moves)
     1935                if (reload)
    19531936                {
    19541937                    NSArray * sorted = [[group torrents] sortedArrayUsingDescriptors: descriptors];
    1955                     [moves addObjectsFromArray: [self rearrangeTorrentArray: [group torrents] to: sorted forParent: group]];
     1938                    [self rearrangeTorrentArray: [group torrents] to: sorted forParent: group beganTableUpdate: &beganTableUpdate];
    19561939                }
    19571940                else
     
    19621945    else
    19631946    {
    1964         if (moves)
     1947        if (reload)
    19651948        {
    19661949            NSArray * sorted = [fDisplayedTorrents sortedArrayUsingDescriptors: descriptors];
    1967             [moves setArray: [self rearrangeTorrentArray: fDisplayedTorrents to: sorted forParent: nil]];
     1950            [self rearrangeTorrentArray: fDisplayedTorrents to: sorted forParent: nil beganTableUpdate: &beganTableUpdate];
    19681951        }
    19691952        else
     
    19711954    }
    19721955   
     1956    if (beganTableUpdate)
     1957    {
     1958        if ([NSApp isOnLionOrBetter])
     1959            [fTableView endUpdates];
     1960        else
     1961            [fTableView reloadData];
     1962    }
     1963   
    19731964    [descriptors release];
    19741965}
    19751966
    1976 - (NSArray *) rearrangeTorrentArray: (NSMutableArray *) rearrangeArray to: (NSArray *) endingArray forParent: parent
     1967- (void) rearrangeTorrentArray: (NSMutableArray *) rearrangeArray to: (NSArray *) endingArray forParent: parent beganTableUpdate: (BOOL *) beganTableUpdate
    19771968{
    19781969    NSAssert2([rearrangeArray count] == [endingArray count], @"Torrent arrays aren't equal size: %d and %d", [rearrangeArray count], [endingArray count]);
    19791970   
    1980     NSMutableArray * moves = [NSMutableArray array];
    19811971    for (NSUInteger currentIndex = 0; currentIndex < [rearrangeArray count]; ++currentIndex)
    19821972    {
     
    19881978            NSAssert3(previousIndex != NSNotFound, @"Expected torrent %@ not found! %@ %@", torrent, rearrangeArray, endingArray);
    19891979           
     1980            if (beganTableUpdate && !*beganTableUpdate)
     1981            {
     1982                *beganTableUpdate = YES;
     1983                if ([NSApp isOnLionOrBetter])
     1984                    [fTableView beginUpdates];
     1985            }
     1986           
    19901987            [rearrangeArray moveObjectAtIndex: previousIndex toIndex: currentIndex];
    1991            
    1992             NSMutableDictionary * move = [NSMutableDictionary dictionaryWithCapacity: parent ? 3 : 2];
    1993             [move setObject: [NSNumber numberWithUnsignedInteger: previousIndex] forKey: @"From"];
    1994             [move setObject: [NSNumber numberWithUnsignedInteger: currentIndex] forKey: @"To"];
    1995             if (parent)
    1996                 [move setObject: parent forKey: @"Parent"];
    1997            
    1998             [moves addObject: move];
     1988            if ([NSApp isOnLionOrBetter])
     1989                [fTableView moveItemAtIndex: previousIndex inParent: parent toIndex: currentIndex inParent: parent];
    19991990        }
    20001991    }
    20011992   
    20021993    NSAssert2([rearrangeArray isEqualToArray: endingArray], @"Torrent rearranging didn't work! %@ %@", rearrangeArray, endingArray);
    2003    
    2004     return moves;
    20051994}
    20061995
     
    21882177   
    21892178    //actually sort
    2190     [self sortTorrentsIgnoreSelected: NULL includeQueueOrder: NO];
     2179    [self sortTorrentsIgnoreSelectedReloadTable: NO includeQueueOrder: NO];
    21912180    [fTableView reloadData];
    21922181   
Note: See TracChangeset for help on using the changeset viewer.