(libT) micro-optimizations suggested by cachegrind

This commit is contained in:
Charles Kerr
2008-11-03 17:01:08 +00:00
parent 2b6fd3412a
commit 5d35dfaeca
2 changed files with 14 additions and 7 deletions
+11 -5
View File
@@ -303,13 +303,19 @@ tr_cpGetStatus( const tr_completion * cp )
uint64_t
tr_cpHaveValid( const tr_completion * cp )
{
uint64_t b = 0;
tr_piece_index_t i;
const tr_torrent * tor = cp->tor;
uint64_t b = 0;
tr_piece_index_t i;
const tr_torrent * tor = cp->tor;
const uint64_t pieceSize = tor->info.pieceSize;
const uint64_t lastPieceSize = tor->lastPieceSize;
const tr_piece_index_t lastPiece = tor->info.pieceCount - 1;
for( i = 0; i < tor->info.pieceCount; ++i )
for( i=0; i!=lastPiece; ++i )
if( tr_cpPieceIsComplete( cp, i ) )
b += tr_torPieceCountBytes( tor, i );
b += pieceSize;
if( tr_cpPieceIsComplete( cp, lastPiece ) )
b += lastPieceSize;
return b;
}
+3 -2
View File
@@ -99,8 +99,9 @@ tr_torrentFindFromHash( tr_handle * handle,
tr_torrent * tor = NULL;
while( ( tor = tr_torrentNext( handle, tor ) ) )
if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
return tor;
if( *tor->info.hash == *torrentHash )
if( !memcmp( tor->info.hash, torrentHash, SHA_DIGEST_LENGTH ) )
return tor;
return NULL;
}