Ignore:
Timestamp:
Mar 29, 2011, 1:17:18 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) more completion and bitfield cleanup: (1) fix regression in tr_cpSizeWhenDone() reported by Waldorf, (2) make simple one-liner functions inlined

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r12248 r12251  
    3737}
    3838
    39 void
    40 tr_cpDestruct( tr_completion * cp )
    41 {
    42     tr_bitfieldDestruct( &cp->blockBitfield );
    43 }
    44 
    4539bool
    4640tr_cpBlockInit( tr_completion * cp, const tr_bitfield * b )
     
    6660***/
    6761
    68 static inline bool
    69 isSeed( const tr_completion * cp )
    70 {
    71     return tr_bitfieldHasAll( &cp->blockBitfield );
    72 }
    73 
    7462tr_completeness
    7563tr_cpGetStatus( const tr_completion * cp )
    7664{
    77     if( isSeed( cp ) ) return TR_SEED;
     65    if( tr_cpHasAll( cp ) ) return TR_SEED;
    7866    if( !tr_torrentHasMetadata( cp->tor ) ) return TR_LEECH;
    7967    if( cp->sizeNow == tr_cpSizeWhenDone( cp ) ) return TR_PARTIAL_SEED;
    8068    return TR_LEECH;
    81 }
    82 
    83 void
    84 tr_cpInvalidateDND( tr_completion * cp )
    85 {
    86     cp->sizeWhenDoneIsDirty = true;
    8769}
    8870
     
    160142    if( ccp->sizeWhenDoneIsDirty )
    161143    {
    162         tr_piece_index_t i;
    163144        uint64_t size = 0;
     145        const tr_torrent * tor = ccp->tor;
    164146        tr_completion * cp = (tr_completion *) ccp; /* mutable */
    165         const tr_torrent * tor = ccp->tor;
    166         const tr_info * info = &tor->info;
    167 
    168         for( i=0; i<info->pieceCount; ++i )
    169             if( !info->pieces[i].dnd || tr_cpPieceIsComplete( cp, i ) )
    170                 size += tr_torPieceCountBytes( tor, i );
     147
     148        if( tr_cpHasAll( ccp ) )
     149        {
     150            size = tor->info.totalSize;
     151        }
     152        else
     153        {
     154            tr_piece_index_t p;
     155
     156            for( p=0; p<tor->info.pieceCount; ++p )
     157            {
     158                if( !tor->info.pieces[p].dnd )
     159                {
     160                    size += tr_torPieceCountBytes( tor, p );
     161                }
     162                else
     163                {
     164                    tr_block_index_t b, f, l;
     165                    tr_torGetPieceBlockRange( cp->tor, p, &f, &l );
     166                    for( b=f; b<=l; ++b )
     167                        if( tr_cpBlockIsComplete( cp, b ) )
     168                            size += tr_torBlockCountBytes( tor, b );
     169                }
     170            }
     171        }
    171172
    172173        cp->sizeWhenDoneLazy = size;
     
    177178}
    178179
    179 uint64_t
    180 tr_cpLeftUntilDone( const tr_completion * cp )
    181 {
    182     return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
    183 }
    184 
    185 uint64_t
    186 tr_cpLeftUntilComplete( const tr_completion * cp )
    187 {
    188     return cp->tor->info.totalSize - cp->sizeNow;
    189 }
    190 
    191180void
    192181tr_cpGetAmountDone( const tr_completion * cp, float * tab, int tabCount )
    193182{
    194183    int i;
    195     const bool seed = isSeed( cp );
     184    const bool seed = tr_cpHasAll( cp );
    196185    const float interval = cp->tor->info.pieceCount / (float)tabCount;
    197186
     
    212201tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
    213202{
    214     if( isSeed( cp ) )
     203    if( tr_cpHasAll( cp ) )
    215204        return 0;
    216205    else {
     
    224213tr_cpMissingBytesInPiece( const tr_completion * cp, tr_piece_index_t piece )
    225214{
    226     if( isSeed( cp ) )
     215    if( tr_cpHasAll( cp ) )
    227216        return 0;
    228217    else {
Note: See TracChangeset for help on using the changeset viewer.