(trunk libT) omit some unnecessary tests on the bitfield checks. these seem small, but bitfields are always the top CPU abuser when I profile...

This commit is contained in:
Charles Kerr 2009-04-11 03:24:36 +00:00
parent afe11e1386
commit f4dde1eb67
5 changed files with 19 additions and 14 deletions

View File

@ -82,11 +82,10 @@ tr_cpSizeWhenDone( const tr_completion * ccp )
{ {
/* we have part of the piece... */ /* we have part of the piece... */
const tr_block_index_t b = tr_torPieceFirstBlock( tor, i ); const tr_block_index_t b = tr_torPieceFirstBlock( tor, i );
const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i );
i ); tr_block_index_t j;
tr_block_index_t j;
for( j = b; j < e; ++j ) for( j = b; j < e; ++j )
if( tr_cpBlockIsComplete( cp, j ) ) if( tr_cpBlockIsCompleteFast( cp, j ) )
size += tr_torBlockCountBytes( tor, j ); size += tr_torBlockCountBytes( tor, j );
} }
} }
@ -129,7 +128,7 @@ tr_cpPieceRem( tr_completion * cp,
assert( end <= tor->blockCount ); assert( end <= tor->blockCount );
for( block = start; block < end; ++block ) for( block = start; block < end; ++block )
if( tr_cpBlockIsComplete( cp, block ) ) if( tr_cpBlockIsCompleteFast( cp, block ) )
cp->sizeNow -= tr_torBlockCountBytes( tor, block ); cp->sizeNow -= tr_torBlockCountBytes( tor, block );
cp->sizeWhenDoneIsDirty = 1; cp->sizeWhenDoneIsDirty = 1;
@ -343,7 +342,7 @@ tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t fileIndex )
firstBlock, lastBlock ); firstBlock, lastBlock );
for( block=firstBlock; block<=lastBlock; ++block ) for( block=firstBlock; block<=lastBlock; ++block )
if( !tr_cpBlockIsComplete( cp, block ) ) if( !tr_cpBlockIsCompleteFast( cp, block ) )
return FALSE; return FALSE;
return TRUE; return TRUE;

View File

@ -135,7 +135,13 @@ tr_bool tr_cpFileIsComplete( const tr_completion * cp, tr_file_index_t );
*** Blocks *** 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 ); return tr_bitfieldHas( &cp->blockBitfield, block );
} }

View File

@ -693,7 +693,7 @@ blockIteratorNext( struct tr_blockIterator * i, tr_block_index_t * setme )
i->blockCount = 0; i->blockCount = 0;
i->blockIndex = 0; i->blockIndex = 0;
for( block=b; block!=e; ++block ) for( block=b; block!=e; ++block )
if( !tr_cpBlockIsComplete( &tor->completion, block ) ) if( !tr_cpBlockIsCompleteFast( &tor->completion, block ) )
i->blocks[i->blockCount++] = block; i->blocks[i->blockCount++] = block;
} }

View File

@ -907,7 +907,7 @@ tr_torrentStat( tr_torrent * tor )
tr_bitfield * peerPieces = tr_peerMgrGetAvailable( tor ); tr_bitfield * peerPieces = tr_peerMgrGetAvailable( tor );
s->desiredAvailable = 0; s->desiredAvailable = 0;
for( i = 0; i < tor->info.pieceCount; ++i ) 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 += tr_cpMissingBlocksInPiece( &tor->completion, i );
s->desiredAvailable *= tor->blockSize; s->desiredAvailable *= tor->blockSize;
tr_bitfieldFree( peerPieces ); tr_bitfieldFree( peerPieces );
@ -992,21 +992,21 @@ fileBytesCompleted( const tr_torrent * tor,
if( firstBlock == lastBlock ) if( firstBlock == lastBlock )
{ {
if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) ) if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
haveBytes += lastBlockOffset + 1 - firstBlockOffset; haveBytes += lastBlockOffset + 1 - firstBlockOffset;
} }
else else
{ {
tr_block_index_t i; tr_block_index_t i;
if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) ) if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
haveBytes += tor->blockSize - firstBlockOffset; haveBytes += tor->blockSize - firstBlockOffset;
for( i = firstBlock + 1; i < lastBlock; ++i ) for( i = firstBlock + 1; i < lastBlock; ++i )
if( tr_cpBlockIsComplete( &tor->completion, i ) ) if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
haveBytes += tor->blockSize; haveBytes += tor->blockSize;
if( tr_cpBlockIsComplete( &tor->completion, lastBlock ) ) if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) )
haveBytes += lastBlockOffset + 1; haveBytes += lastBlockOffset + 1;
} }

View File

@ -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 ) 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 );
} }
/*** /***