Ignore:
Timestamp:
Jan 2, 2009, 5:01:55 PM (13 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_completion, contain the it directly rather than a pointer to one allocated elsewhere on the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r7576 r7578  
    3131#include "utils.h"
    3232
    33 struct tr_completion
    34 {
    35     tr_bool  sizeWhenDoneIsDirty;
    36     tr_bool  haveValidIsDirty;
    37 
    38     tr_torrent *    tor;
    39 
    40     /* do we have this block? */
    41     tr_bitfield    blockBitfield;
    42 
    43     /* do we have this piece? */
    44     tr_bitfield    pieceBitfield;
    45 
    46     /* a block is complete if and only if we have it */
    47     uint16_t *  completeBlocks;
    48 
    49     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    50        DON'T access this directly; it's a lazy field.
    51        use tr_cpSizeWhenDone() instead! */
    52     uint64_t    sizeWhenDoneLazy;
    53 
    54     /* number of bytes we'll have when done downloading. [0..info.totalSize]
    55        DON'T access this directly; it's a lazy field.
    56        use tr_cpHaveValid() instead! */
    57     uint64_t    haveValidLazy;
    58 
    59     /* number of bytes we want or have now. [0..sizeWhenDone] */
    60     uint64_t    sizeNow;
    61 };
    62 
    6333static void
    6434tr_cpReset( tr_completion * cp )
     
    7444
    7545tr_completion *
    76 tr_cpInit( tr_torrent * tor )
    77 {
    78     tr_completion * cp  = tr_new( tr_completion, 1 );
    79 
    80     cp->tor             = tor;
     46tr_cpConstruct( tr_completion * cp, tr_torrent * tor )
     47{
     48    cp->tor = tor;
    8149    cp->completeBlocks  = tr_new( uint16_t, tor->info.pieceCount );
    8250    tr_bitfieldConstruct( &cp->blockBitfield, tor->blockCount );
     
    8654}
    8755
    88 void
    89 tr_cpClose( tr_completion * cp )
     56tr_completion*
     57tr_cpDestruct( tr_completion * cp )
    9058{
    9159    tr_free( cp->completeBlocks );
    9260    tr_bitfieldDestruct( &cp->pieceBitfield );
    9361    tr_bitfieldDestruct( &cp->blockBitfield );
    94     tr_free        ( cp );
     62    return cp;
    9563}
    9664
     
    146114}
    147115
    148 int
    149 tr_cpPieceIsComplete( const tr_completion * cp,
    150                       tr_piece_index_t      piece )
    151 {
    152     return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
    153 }
    154 
    155 const tr_bitfield *
    156 tr_cpPieceBitfield( const tr_completion * cp )
    157 {
    158     return &cp->pieceBitfield;
    159 }
    160 
    161116void
    162117tr_cpPieceAdd( tr_completion *  cp,
     
    198153}
    199154
    200 int
    201 tr_cpBlockIsComplete( const tr_completion * cp,
    202                       tr_block_index_t      block )
    203 {
    204     return tr_bitfieldHas( &cp->blockBitfield, block );
    205 }
    206 
    207155void
    208156tr_cpBlockAdd( tr_completion *  cp,
     
    229177        cp->sizeWhenDoneIsDirty = 1;
    230178    }
    231 }
    232 
    233 const tr_bitfield *
    234 tr_cpBlockBitfield( const tr_completion * cp )
    235 {
    236     assert( cp );
    237     assert( cp->blockBitfield.bits );
    238     assert( cp->blockBitfield.bitCount );
    239 
    240     return &cp->blockBitfield;
    241179}
    242180
     
    263201}
    264202
    265 int
    266 tr_cpMissingBlocksInPiece( const tr_completion * cp,
    267                            tr_piece_index_t      piece )
    268 {
    269     return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece];
    270 }
    271 
    272203/***
    273204****
    274205***/
    275 
    276 float
    277 tr_cpPercentDone( const tr_completion * cp )
    278 {
    279     return tr_getRatio( cp->sizeNow, tr_cpSizeWhenDone( cp ) );
    280 }
    281 
    282 float
    283 tr_cpPercentComplete( const tr_completion * cp )
    284 {
    285     return tr_getRatio( cp->sizeNow, cp->tor->info.totalSize );
    286 }
    287 
    288 uint64_t
    289 tr_cpLeftUntilDone( const tr_completion * cp )
    290 {
    291     return tr_cpSizeWhenDone( cp ) - cp->sizeNow;
    292 }
    293 
    294 uint64_t
    295 tr_cpLeftUntilComplete( const tr_completion * cp )
    296 {
    297     return cp->tor->info.totalSize - cp->sizeNow;
    298 }
    299206
    300207tr_completeness
     
    339246}
    340247
    341 uint64_t
    342 tr_cpHaveTotal( const tr_completion * cp )
    343 {
    344     return cp->sizeNow;
    345 }
    346 
    347248void
    348249tr_cpGetAmountDone( const tr_completion * cp,
     
    353254    const tr_torrent * tor = cp->tor;
    354255    const float        interval = tor->info.pieceCount / (float)tabCount;
    355     const int          isSeed = tr_cpGetStatus ( tor->completion ) == TR_SEED;
     256    const int          isSeed = tr_cpGetStatus( cp ) == TR_SEED;
    356257
    357258    for( i = 0; i < tabCount; ++i )
     
    368269    }
    369270}
     271
     272int
     273tr_cpMissingBlocksInPiece( const tr_completion * cp, tr_piece_index_t piece )
     274{
     275    return tr_torPieceCountBlocks( cp->tor, piece ) - cp->completeBlocks[piece];
     276}
     277
     278
     279int
     280tr_cpPieceIsComplete( const tr_completion * cp, tr_piece_index_t piece )
     281{
     282    return cp->completeBlocks[piece] == tr_torPieceCountBlocks( cp->tor, piece );
     283}
Note: See TracChangeset for help on using the changeset viewer.