Ignore:
Timestamp:
Jul 28, 2007, 10:47:10 PM (14 years ago)
Author:
charles
Message:
  • now that we've got a new function at the top of the CPU hog list, tweak it too.
  • reduce large torrents' memory consumption in tr_completion_t.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r2531 r2538  
    3030    tr_torrent_t * tor;
    3131
    32     /* number of peers from whom we've requested this block */
    33     uint8_t * blockDownloaders;
     32    /* true if a peer is requesting this block */
     33    tr_bitfield_t * blockRequested;
    3434
    3535    /* do we have this block? */
     
    5555    cp->tor              = tor;
    5656    cp->blockBitfield    = tr_bitfieldNew( tor->blockCount );
    57     cp->blockDownloaders = tr_new( uint8_t, tor->blockCount );
     57    cp->blockRequested   = tr_bitfieldNew( tor->blockCount );
    5858    cp->pieceBitfield    = tr_bitfieldNew( tor->info.pieceCount );
    5959    cp->completeBlocks   = tr_new( uint16_t, tor->info.pieceCount );
     
    6868    tr_free(         cp->completeBlocks );
    6969    tr_bitfieldFree( cp->pieceBitfield );
    70     tr_free(         cp->blockDownloaders );
     70    tr_bitfieldFree( cp->blockRequested );
    7171    tr_bitfieldFree( cp->blockBitfield );
    7272    tr_free(         cp );
     
    7777    tr_torrent_t * tor = cp->tor;
    7878
     79    tr_bitfieldClear( cp->pieceBitfield );
    7980    tr_bitfieldClear( cp->blockBitfield );
    80     memset( cp->blockDownloaders, 0, tor->blockCount );
    81     tr_bitfieldClear( cp->pieceBitfield );
     81    tr_bitfieldClear( cp->blockRequested );
    8282    memset( cp->completeBlocks, 0, sizeof(uint16_t) * tor->info.pieceCount );
    8383
     
    195195void tr_cpDownloaderAdd( tr_completion_t * cp, int block )
    196196{
    197     ++cp->blockDownloaders[block];
     197    tr_bitfieldAdd( cp->blockRequested, block );
    198198}
    199199
    200200void tr_cpDownloaderRem( tr_completion_t * cp, int block )
    201201{
    202     --cp->blockDownloaders[block];
     202    tr_bitfieldRem( cp->blockRequested, block );
    203203}
    204204
     
    272272    n = 0;
    273273    for( i = start; i < end; ++i )
    274         if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
     274        if( !tr_cpBlockIsComplete( cp, i ) && !tr_bitfieldHas( cp->blockRequested, i ) )
    275275            ++n;
    276276
     
    286286
    287287    for( i = start; i < end; ++i )
    288         if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
     288        if( !tr_cpBlockIsComplete( cp, i ) && !tr_bitfieldHas( cp->blockRequested, i ) )
    289289            return i;
    290290
Note: See TracChangeset for help on using the changeset viewer.