Changeset 12251


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

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bitfield.c

    r12248 r12251  
    203203}
    204204
    205 void
    206 tr_bitfieldDestruct( tr_bitfield * b )
    207 {
    208     tr_bitfieldSetHasNone( b );
    209 }
    210 
    211205static void
    212206tr_bitfieldClear( tr_bitfield * b )
  • trunk/libtransmission/bitfield.h

    r12248 r12251  
    3737
    3838/***
    39 ****  life cycle
    40 ***/
    41 
    42 extern const tr_bitfield TR_BITFIELD_INIT;
    43 
    44 void   tr_bitfieldConstruct( tr_bitfield*, size_t bit_count );
    45 
    46 void   tr_bitfieldDestruct( tr_bitfield* );
    47 
    48 /***
    4939****
    5040***/
     
    6151
    6252void   tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
     53
     54/***
     55****  life cycle
     56***/
     57
     58extern const tr_bitfield TR_BITFIELD_INIT;
     59
     60void   tr_bitfieldConstruct( tr_bitfield*, size_t bit_count );
     61
     62static inline void
     63tr_bitfieldDestruct( tr_bitfield * b )
     64{
     65    tr_bitfieldSetHasNone( b );
     66}
    6367
    6468/***
  • 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 {
  • trunk/libtransmission/completion.h

    r12248 r12251  
    2626    tr_torrent * tor;
    2727
    28     /* do we have this block? */
    2928    tr_bitfield blockBitfield;
    3029
     
    5453**/
    5554
    56 void              tr_cpConstruct( tr_completion *, tr_torrent * );
     55void  tr_cpConstruct( tr_completion *, tr_torrent * );
    5756
    58 void              tr_cpDestruct( tr_completion * );
     57bool  tr_cpBlockInit( tr_completion * cp, const tr_bitfield * blocks );
     58
     59static inline void
     60tr_cpDestruct( tr_completion * cp )
     61{
     62    tr_bitfieldDestruct( &cp->blockBitfield );
     63}
    5964
    6065/**
     
    7277uint64_t          tr_cpSizeWhenDone( const tr_completion * );
    7378
    74 uint64_t          tr_cpLeftUntilComplete( const tr_completion * );
    75 
    76 uint64_t          tr_cpLeftUntilDone( const tr_completion * );
    77 
    7879void              tr_cpGetAmountDone( const   tr_completion * completion,
    7980                                      float                 * tab,
    8081                                      int                     tabCount );
     82
     83
     84static inline uint64_t
     85tr_cpHaveTotal( const tr_completion * cp )
     86{
     87    return cp->sizeNow;
     88}
     89
     90static inline uint64_t
     91tr_cpLeftUntilComplete( const tr_completion * cp )
     92{
     93    return tr_torrentInfo(cp->tor)->totalSize - cp->sizeNow;
     94}
     95
     96static inline uint64_t
     97tr_cpLeftUntilDone( const tr_completion * cp )
     98{
     99    return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
     100}
    81101
    82102static inline bool tr_cpHasAll( const tr_completion * cp )
     
    88108{
    89109    return tr_bitfieldHasNone( &cp->blockBitfield );
    90 }
    91 
    92 static inline uint64_t tr_cpHaveTotal( const tr_completion * cp )
    93 {
    94     return cp->sizeNow;
    95110}
    96111
     
    117132**/
    118133
     134void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
     135
    119136static inline bool
    120137tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t i )
     
    122139    return tr_bitfieldHas( &cp->blockBitfield, i );
    123140}
    124 
    125 void  tr_cpBlockAdd( tr_completion * cp, tr_block_index_t i );
    126 
    127 bool  tr_cpBlockInit( tr_completion * cp, const tr_bitfield * blocks );
    128141
    129142/***
     
    133146bool  tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
    134147
    135 void  tr_cpInvalidateDND( tr_completion * );
     148void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
    136149
    137 void* tr_cpCreatePieceBitfield( const tr_completion * cp, size_t * byte_count );
     150static inline void
     151tr_cpInvalidateDND( tr_completion * cp )
     152{
     153    cp->sizeWhenDoneIsDirty = true;
     154}
    138155
    139156
Note: See TracChangeset for help on using the changeset viewer.