Changeset 2479


Ignore:
Timestamp:
Jul 24, 2007, 2:51:46 PM (15 years ago)
Author:
charles
Message:

faster tr_cpGetStatus() and tr_bitfieldHas(), which were showing up at the top of the CPU profile.

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/completion.c

    r2478 r2479  
    100100int tr_cpPieceIsComplete( const tr_completion_t * cp, int piece )
    101101{
    102     return tr_bitfieldHas( cp->pieceBitfield, piece );
     102    return cp->completeBlocks[piece] >= tr_cpCountBlocks(cp,piece);
    103103}
    104104
  • trunk/libtransmission/peerutils.h

    r2477 r2479  
    167167                               int                   piece )
    168168{
     169    if( tor->info.pieces[piece].dnd ) /* we don't want it */
     170        return 0;
     171
    169172    if( tr_cpPieceIsComplete( tor->completion, piece ) ) /* we already have it */
    170         return 0;
    171 
    172     if( tor->info.pieces[piece].dnd ) /* we don't want it */
    173173        return 0;
    174174
  • trunk/libtransmission/utils.c

    r2474 r2479  
    575575}
    576576
    577 static const uint8_t bitmask[8] = { 128u, 64u, 32u, 16u, 8u, 4u, 2u, 1u };
     577#define BIN(nth) (nth>>3)
     578#define BIT(nth) (1<<(7-(nth%8)))
    578579
    579580int
    580581tr_bitfieldHas( const tr_bitfield_t   * bitfield,
    581                 size_t                  bit )
    582 {
    583     if ( bitfield == NULL ) return 0;
    584     assert( bit / 8u < bitfield->len );
    585     return ( bitfield->bits[ bit/8u ] & bitmask[bit%8] ) != 0;
     582                size_t                  nth )
     583{
     584    return bitfield && (bitfield->bits[ BIN(nth) ] & BIT(nth) );
    586585}
    587586
    588587void
    589 tr_bitfieldAdd( tr_bitfield_t  * bitfield, size_t bit )
    590 {
    591     assert( bit / 8u < bitfield->len );
    592     bitfield->bits[ bit/8u ] |= bitmask[bit%8];
     588tr_bitfieldAdd( tr_bitfield_t  * bitfield, size_t nth )
     589{
     590    bitfield->bits[ BIN(nth) ] |= BIT(nth);
    593591}
    594592
     
    606604void
    607605tr_bitfieldRem( tr_bitfield_t   * bitfield,
    608                 size_t            bit )
     606                size_t            nth )
    609607{
    610608    if( bitfield != NULL )
    611     {
    612         assert( bit / 8u < bitfield->len );
    613         bitfield->bits[bit/8u] &= ~bitmask[bit%8];
    614     }
     609        bitfield->bits[BIN(nth)] &= ~BIT(nth);
    615610}
    616611
Note: See TracChangeset for help on using the changeset viewer.