Ignore:
Timestamp:
Dec 29, 2008, 9:51:54 AM (13 years ago)
Author:
charles
Message:

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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r7199 r7525  
    3939
    4040    /* do we have this block? */
    41     tr_bitfield *  blockBitfield;
     41    tr_bitfield    blockBitfield;
    4242
    4343    /* do we have this piece? */
    44     tr_bitfield *  pieceBitfield;
     44    tr_bitfield    pieceBitfield;
    4545
    4646    /* a block is complete if and only if we have it */
     
    6464tr_cpReset( tr_completion * cp )
    6565{
    66     tr_bitfieldClear( cp->pieceBitfield );
    67     tr_bitfieldClear( cp->blockBitfield );
     66    tr_bitfieldClear( &cp->pieceBitfield );
     67    tr_bitfieldClear( &cp->blockBitfield );
    6868    memset( cp->completeBlocks, 0,
    6969            sizeof( uint16_t ) * cp->tor->info.pieceCount );
     
    7979
    8080    cp->tor             = tor;
    81     cp->blockBitfield   = tr_bitfieldNew( tor->blockCount );
    82     cp->pieceBitfield   = tr_bitfieldNew( tor->info.pieceCount );
    8381    cp->completeBlocks  = tr_new( uint16_t, tor->info.pieceCount );
     82    tr_bitfieldConstruct( &cp->blockBitfield, tor->blockCount );
     83    tr_bitfieldConstruct( &cp->pieceBitfield, tor->info.pieceCount );
    8484    tr_cpReset( cp );
    8585    return cp;
     
    8989tr_cpClose( tr_completion * cp )
    9090{
    91     tr_free        ( cp->completeBlocks );
    92     tr_bitfieldFree( cp->pieceBitfield );
    93     tr_bitfieldFree( cp->blockBitfield );
     91    tr_free( cp->completeBlocks );
     92    tr_bitfieldDestruct( &cp->pieceBitfield );
     93    tr_bitfieldDestruct( &cp->blockBitfield );
    9494    tr_free        ( cp );
    9595}
     
    156156tr_cpPieceBitfield( const tr_completion * cp )
    157157{
    158     return cp->pieceBitfield;
     158    return &cp->pieceBitfield;
    159159}
    160160
     
    194194    cp->haveValidIsDirty = 1;
    195195    cp->completeBlocks[piece] = 0;
    196     tr_bitfieldRemRange ( cp->blockBitfield, start, end );
    197     tr_bitfieldRem( cp->pieceBitfield, piece );
     196    tr_bitfieldRemRange ( &cp->blockBitfield, start, end );
     197    tr_bitfieldRem( &cp->pieceBitfield, piece );
    198198}
    199199
     
    202202                      tr_block_index_t      block )
    203203{
    204     return tr_bitfieldHas( cp->blockBitfield, block );
     204    return tr_bitfieldHas( &cp->blockBitfield, block );
    205205}
    206206
     
    220220
    221221        if( tr_cpPieceIsComplete( cp, piece ) )
    222             tr_bitfieldAdd( cp->pieceBitfield, piece );
    223 
    224         tr_bitfieldAdd( cp->blockBitfield, block );
     222            tr_bitfieldAdd( &cp->pieceBitfield, piece );
     223
     224        tr_bitfieldAdd( &cp->blockBitfield, block );
    225225
    226226        cp->sizeNow += blockSize;
     
    235235{
    236236    assert( cp );
    237     assert( cp->blockBitfield );
    238     assert( cp->blockBitfield->bits );
    239     assert( cp->blockBitfield->bitCount );
    240 
    241     return cp->blockBitfield;
     237    assert( cp->blockBitfield.bits );
     238    assert( cp->blockBitfield.bitCount );
     239
     240    return &cp->blockBitfield;
    242241}
    243242
     
    250249    assert( cp );
    251250    assert( bitfield );
    252     assert( cp->blockBitfield );
    253251
    254252    if( tr_bitfieldTestFast( bitfield, cp->tor->blockCount - 1 ) )
Note: See TracChangeset for help on using the changeset viewer.