Changeset 13135


Ignore:
Timestamp:
Jan 7, 2012, 5:08:28 PM (10 years ago)
Author:
livings124
Message:

re-add code (removed in r13132) to remove previous piece information for no-longer-displayed torrents (in a fun new block way!)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/macosx/Controller.m

    r13134 r13135  
    20322032- (void) applyFilter
    20332033{
    2034     #warning re-add
    2035     //get all the torrents in the table
    2036     /*NSMutableArray * previousTorrents;
    2037     if ([fDisplayedTorrents count] > 0 && [[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])
    2038     {
    2039         previousTorrents = [NSMutableArray array];
    2040        
    2041         for (TorrentGroup * group in fDisplayedTorrents)
    2042             [previousTorrents addObjectsFromArray: [group torrents]];
    2043     }
    2044     else
    2045         previousTorrents = fDisplayedTorrents;*/
    2046    
    20472034    const BOOL onLion = [NSApp isOnLionOrBetter];
    20482035   
     
    21592146        [fFilterBar setCountAll: [fTorrents count] active: active downloading: downloading seeding: seeding paused: paused];
    21602147   
     2148    #warning could probably be merged with later code somehow
    21612149    //clear display cache for not-shown torrents
    2162     /*[previousTorrents removeObjectsInArray: allTorrents];
    2163     for (Torrent * torrent in previousTorrents)
    2164         [torrent setPreviousFinishedPieces: nil];*/
     2150    if ([fDisplayedTorrents count] > 0)
     2151    {
     2152        NSMutableIndexSet * unusedIndexesInAll = [NSMutableIndexSet indexSetWithIndexesInRange: NSMakeRange(0, [allTorrents count])];
     2153       
     2154        //for each torrent, removes the previous piece info if it's not in allTorrents, and keeps track of which torrents we already found in allTorrents
     2155        void (^removePreviousFinishedPieces)(id, NSUInteger, BOOL *) = ^(id objDisplay, NSUInteger idx, BOOL * stop) {
     2156            const NSUInteger index = [allTorrents indexOfObjectAtIndexes: unusedIndexesInAll options: NSEnumerationConcurrent passingTest: ^BOOL(id objAll, NSUInteger idxAll, BOOL * stopAll) {
     2157                return objDisplay == objAll;
     2158            }];
     2159           
     2160            if (index == NSNotFound)
     2161                [(Torrent *)objDisplay setPreviousFinishedPieces: nil];
     2162            else
     2163                [unusedIndexesInAll removeIndex: index];
     2164        };
     2165       
     2166        if ([[fDisplayedTorrents objectAtIndex: 0] isKindOfClass: [TorrentGroup class]])
     2167            for (TorrentGroup * group in fDisplayedTorrents)
     2168                [[group torrents] enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: removePreviousFinishedPieces];
     2169        else
     2170            [fDisplayedTorrents enumerateObjectsWithOptions: NSEnumerationConcurrent usingBlock: removePreviousFinishedPieces];
     2171    }
    21652172   
    21662173    BOOL beganUpdates = NO;
Note: See TracChangeset for help on using the changeset viewer.