Changeset 12902


Ignore:
Timestamp:
Sep 20, 2011, 11:39:40 PM (10 years ago)
Author:
jordan
Message:

#4496 'freeze when having a huge torrent' -- add a bitfield helper function to init the bitfield from an array of flags.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bitfield.c

    r12554 r12902  
    302302
    303303void
     304tr_bitfieldSetFromFlags( tr_bitfield * b, const bool * flags, size_t n )
     305{
     306    size_t i;
     307    size_t trueCount = 0;
     308
     309    tr_bitfieldFreeArray( b );
     310    tr_bitfieldEnsureBitsAlloced( b, n );
     311
     312    for( i=0; i<n; ++i )
     313    {
     314        if( flags[i] )
     315        {
     316            ++trueCount;
     317            b->bits[i >> 3u] |= ( 0x80 >> ( i & 7u ) );
     318        }
     319    }
     320
     321    tr_bitfieldSetTrueCount( b, trueCount );
     322}
     323
     324void
    304325tr_bitfieldAdd( tr_bitfield * b, size_t nth )
    305326{
  • trunk/libtransmission/bitfield.h

    r12307 r12902  
    7171***/
    7272
     73void   tr_bitfieldSetFromFlags( tr_bitfield*, const bool * bytes, size_t n );
     74
    7375void   tr_bitfieldSetFromBitfield( tr_bitfield*, const tr_bitfield* );
    7476
  • trunk/libtransmission/completion.c

    r12531 r12902  
    256256    else if( !tr_cpHasNone( cp ) ) {
    257257        tr_piece_index_t i;
     258        bool * flags = tr_new( bool, n );
    258259        for( i=0; i<n; ++i )
    259             if( tr_cpPieceIsComplete( cp, i ) )
    260                 tr_bitfieldAdd( &pieces, i );
     260            flags[i] = tr_cpPieceIsComplete( cp, i );
     261        tr_bitfieldSetFromFlags( &pieces, flags, n );
     262        tr_free( flags );
    261263    }
    262264
Note: See TracChangeset for help on using the changeset viewer.