Changeset 6058


Ignore:
Timestamp:
Jun 5, 2008, 8:21:56 PM (13 years ago)
Author:
charles
Message:

bitfield speedups written by denis. Thanks!

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r6008 r6058  
    663663        tr_block_index_t block;
    664664
     665        assert( tr_bitfieldTestFast( t->requested, end ) );
     666
    665667        for( block=begin; block<end; ++block )
    666668        {
     
    670672            ++blockCount;
    671673
    672             if( tr_bitfieldHas( t->requested, block ) )
     674            if( tr_bitfieldHasFast( t->requested, block ) )
    673675            {
    674676                const uint32_t n = reqCount[priorityIndex]++;
  • trunk/libtransmission/utils.c

    r5979 r6058  
    698698}
    699699
    700 void tr_bitfieldFree( tr_bitfield * bitfield )
     700void
     701tr_bitfieldFree( tr_bitfield * bitfield )
    701702{
    702703    if( bitfield )
     
    728729tr_bitfieldHas( const tr_bitfield * bitfield, size_t nth )
    729730{
    730     static const uint8_t ands[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
    731     const size_t i = nth >> 3u;
    732     return ( bitfield != NULL )
    733         && ( bitfield->bits != NULL )
    734         && ( i < bitfield->len )
    735         && ( ( bitfield->bits[i] & ands[nth&7u] ) != 0 );
     731    return ( tr_bitfieldTestFast( bitfield, nth ) )
     732        && ( tr_bitfieldHasFast( bitfield, nth ) );
    736733}
    737734
     
    739736tr_bitfieldAdd( tr_bitfield  * bitfield, size_t nth )
    740737{
    741     static const uint8_t ands[8] = { 128, 64, 32, 16, 8, 4, 2, 1 };
    742738    const size_t i = nth >> 3u;
    743739
     
    748744        return -1;
    749745
    750     bitfield->bits[i] |= ands[nth&7u];
     746    bitfield->bits[i] |= (0x80 >> (nth&7u));
    751747    /*assert( tr_bitfieldHas( bitfield, nth ) );*/
    752748    return 0;
     
    770766                size_t          nth )
    771767{
    772     static const uint8_t rems[8] = { 127, 191, 223, 239, 247, 251, 253, 254 };
    773768    const size_t i = nth >> 3u;
    774769
     
    779774        return -1;
    780775
    781     bitfield->bits[i] &= rems[nth&7u];
     776    bitfield->bits[i] &= (0xff7f >> nth&7u);
    782777    /*assert( !tr_bitfieldHas( bitfield, nth ) );*/
    783778    return 0;
  • trunk/libtransmission/utils.h

    r5979 r6058  
    262262tr_bitfield* tr_bitfieldOr( tr_bitfield*, const tr_bitfield* );
    263263
     264/** A stripped-down version of bitfieldHas to be used
     265    for speed when you're looping quickly.  This version
     266    has none of tr_bitfieldHas()'s safety checks, so you
     267    need to call tr_bitfieldTestFast() first before you
     268    start looping. */
     269#define tr_bitfieldHasFast(bitfield,nth) \
     270    (( bitfield->bits[(nth)>>3u] << ((nth)&7u) & 0x80) != 0 )
     271
     272/** @param high the highest nth bit you're going to access */
     273#define tr_bitfieldTestFast(bitfield,high) \
     274    ((bitfield) && ( (bitfield)->bits ) && ( ((high)>>3u) < (bitfield)->len ))
     275
    264276double tr_getRatio( double numerator, double denominator );
    265277
Note: See TracChangeset for help on using the changeset viewer.