From f4dde1eb67e3b7dae16bfe8eb0f2c30a966833f8 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Sat, 11 Apr 2009 03:24:36 +0000 Subject: [PATCH] (trunk libT) omit some unnecessary tests on the bitfield checks. these seem small, but bitfields are always the top CPU abuser when I profile... --- libtransmission/completion.c | 11 +++++------ libtransmission/completion.h | 8 +++++++- libtransmission/peer-mgr.c | 2 +- libtransmission/torrent.c | 10 +++++----- libtransmission/torrent.h | 2 +- 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/libtransmission/completion.c b/libtransmission/completion.c index ef8eeecd8..a6eefd9a1 100644 --- a/libtransmission/completion.c +++ b/libtransmission/completion.c @@ -82,11 +82,10 @@ tr_cpSizeWhenDone( const tr_completion * ccp ) { /* we have part of the piece... */ const tr_block_index_t b = tr_torPieceFirstBlock( tor, i ); - const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, - i ); - tr_block_index_t j; + const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i ); + tr_block_index_t j; for( j = b; j < e; ++j ) - if( tr_cpBlockIsComplete( cp, j ) ) + if( tr_cpBlockIsCompleteFast( cp, j ) ) size += tr_torBlockCountBytes( tor, j ); } } @@ -129,7 +128,7 @@ tr_cpPieceRem( tr_completion * cp, assert( end <= tor->blockCount ); for( block = start; block < end; ++block ) - if( tr_cpBlockIsComplete( cp, block ) ) + if( tr_cpBlockIsCompleteFast( cp, block ) ) cp->sizeNow -= tr_torBlockCountBytes( tor, block ); cp->sizeWhenDoneIsDirty = 1; @@ -343,7 +342,7 @@ tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex ) firstBlock, lastBlock ); for( block=firstBlock; block<=lastBlock; ++block ) - if( !tr_cpBlockIsComplete( cp, block ) ) + if( !tr_cpBlockIsCompleteFast( cp, block ) ) return FALSE; return TRUE; diff --git a/libtransmission/completion.h b/libtransmission/completion.h index 8b556c893..c93773eb7 100644 --- a/libtransmission/completion.h +++ b/libtransmission/completion.h @@ -135,7 +135,13 @@ tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t ); *** Blocks **/ -static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) { +static TR_INLINE tr_bool tr_cpBlockIsCompleteFast( const tr_completion * cp, tr_block_index_t block ) +{ + return tr_bitfieldHasFast( &cp->blockBitfield, block ); +} + +static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) +{ return tr_bitfieldHas( &cp->blockBitfield, block ); } diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index c869b07c8..def33ad3f 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -693,7 +693,7 @@ blockIteratorNext( struct tr_blockIterator * i, tr_block_index_t * setme ) i->blockCount = 0; i->blockIndex = 0; for( block=b; block!=e; ++block ) - if( !tr_cpBlockIsComplete( &tor->completion, block ) ) + if( !tr_cpBlockIsCompleteFast( &tor->completion, block ) ) i->blocks[i->blockCount++] = block; } diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index 41a11feeb..09077ce84 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -907,7 +907,7 @@ tr_torrentStat( tr_torrent * tor ) tr_bitfield * peerPieces = tr_peerMgrGetAvailable( tor ); s->desiredAvailable = 0; for( i = 0; i < tor->info.pieceCount; ++i ) - if( !tor->info.pieces[i].dnd && tr_bitfieldHas( peerPieces, i ) ) + if( !tor->info.pieces[i].dnd && tr_bitfieldHasFast( peerPieces, i ) ) s->desiredAvailable += tr_cpMissingBlocksInPiece( &tor->completion, i ); s->desiredAvailable *= tor->blockSize; tr_bitfieldFree( peerPieces ); @@ -992,21 +992,21 @@ fileBytesCompleted( const tr_torrent * tor, if( firstBlock == lastBlock ) { - if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) ) + if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) ) haveBytes += lastBlockOffset + 1 - firstBlockOffset; } else { tr_block_index_t i; - if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) ) + if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) ) haveBytes += tor->blockSize - firstBlockOffset; for( i = firstBlock + 1; i < lastBlock; ++i ) - if( tr_cpBlockIsComplete( &tor->completion, i ) ) + if( tr_cpBlockIsCompleteFast( &tor->completion, i ) ) haveBytes += tor->blockSize; - if( tr_cpBlockIsComplete( &tor->completion, lastBlock ) ) + if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) ) haveBytes += lastBlockOffset + 1; } diff --git a/libtransmission/torrent.h b/libtransmission/torrent.h index c2e92d977..63582ee47 100644 --- a/libtransmission/torrent.h +++ b/libtransmission/torrent.h @@ -292,7 +292,7 @@ static TR_INLINE tr_bool tr_torrentAllowsPex( const tr_torrent * tor ) static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent * tor, tr_piece_index_t i ) { - return tr_bitfieldHas( &tor->checkedPieces, i ); + return tr_bitfieldHasFast( &tor->checkedPieces, i ); } /*** -- 2.40.0