Ignore:
Timestamp:
Feb 15, 2011, 4:04:56 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) #3656 "endgame could be faster" -- fixed. Patch by harrydb.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r11797 r11892  
    2828    cp->sizeNow = 0;
    2929    cp->sizeWhenDoneIsDirty = 1;
     30    cp->blocksWantedIsDirty = 1;
    3031    cp->haveValidIsDirty = 1;
    3132}
     
    5556{
    5657    cp->sizeWhenDoneIsDirty = 1;
     58    cp->blocksWantedIsDirty = 1;
     59}
     60
     61tr_block_index_t
     62tr_cpBlocksMissing( const tr_completion * ccp )
     63{
     64    if( ccp->blocksWantedIsDirty )
     65    {
     66        tr_completion *    cp = (tr_completion *) ccp; /* mutable */
     67        const tr_torrent * tor = cp->tor;
     68        const tr_info *    info = &tor->info;
     69        tr_piece_index_t   i;
     70        tr_block_index_t   wanted = 0;
     71        tr_block_index_t   complete = 0;
     72
     73        for( i = 0; i < info->pieceCount; ++i )
     74        {
     75            if( info->pieces[i].dnd )
     76                continue;
     77
     78            wanted += tr_torPieceCountBlocks( tor, i );
     79            complete += cp->completeBlocks[i];
     80        }
     81
     82        cp->blocksWantedLazy = wanted;
     83        cp->blocksWantedCompleteLazy = complete;
     84        cp->blocksWantedIsDirty = FALSE;
     85    }
     86
     87    return ccp->blocksWantedLazy - ccp->blocksWantedCompleteLazy;
    5788}
    5889
     
    133164            cp->sizeNow -= tr_torBlockCountBytes( tor, block );
    134165
     166    if( !tor->info.pieces[piece].dnd )
     167        cp->blocksWantedCompleteLazy -= cp->completeBlocks[piece];
     168
    135169    cp->sizeWhenDoneIsDirty = 1;
    136170    cp->haveValidIsDirty = 1;
     
    159193
    160194        cp->sizeNow += blockSize;
     195        if( !tor->info.pieces[piece].dnd )
     196            cp->blocksWantedCompleteLazy++;
    161197
    162198        cp->haveValidIsDirty = 1;
     
    180216        cp->completeBlocks[i] = tr_torPieceCountBlocks( tor, i );
    181217    cp->sizeWhenDoneIsDirty = 1;
     218    cp->blocksWantedIsDirty = 1;
    182219    cp->haveValidIsDirty = 1;
    183220}
     
    211248        /* invalidate the fields that are lazy-evaluated */
    212249        cp->sizeWhenDoneIsDirty = TRUE;
     250        cp->blocksWantedIsDirty = TRUE;
    213251        cp->haveValidIsDirty = TRUE;
    214252
Note: See TracChangeset for help on using the changeset viewer.