1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

(trunk libT) faster tr_cpBlockBitfieldSet()

This commit is contained in:
Charles Kerr 2009-01-06 07:45:15 +00:00
parent 2a6c7dd0fa
commit 7581f04242

View file

@ -35,8 +35,7 @@ tr_cpReset( tr_completion * cp )
{ {
tr_bitfieldClear( &cp->pieceBitfield ); tr_bitfieldClear( &cp->pieceBitfield );
tr_bitfieldClear( &cp->blockBitfield ); tr_bitfieldClear( &cp->blockBitfield );
memset( cp->completeBlocks, 0, memset( cp->completeBlocks, 0, sizeof( uint16_t ) * cp->tor->info.pieceCount );
sizeof( uint16_t ) * cp->tor->info.pieceCount );
cp->sizeNow = 0; cp->sizeNow = 0;
cp->sizeWhenDoneIsDirty = 1; cp->sizeWhenDoneIsDirty = 1;
cp->haveValidIsDirty = 1; cp->haveValidIsDirty = 1;
@ -178,6 +177,7 @@ tr_cpBlockAdd( tr_completion * cp,
} }
} }
#if 0
int int
tr_cpBlockBitfieldSet( tr_completion * cp, tr_cpBlockBitfieldSet( tr_completion * cp,
tr_bitfield * bitfield ) tr_bitfield * bitfield )
@ -199,6 +199,52 @@ tr_cpBlockBitfieldSet( tr_completion * cp,
return success; return success;
} }
#endif
int
tr_cpBlockBitfieldSet( tr_completion * cp, tr_bitfield * blockBitfield )
{
int success = FALSE;
assert( cp );
assert( blockBitfield );
if(( success = tr_bitfieldTestFast( blockBitfield, cp->tor->blockCount - 1 )))
{
tr_piece_index_t p;
const tr_torrent * tor = cp->tor;
tr_cpReset( cp );
for( p=0; p<tor->info.pieceCount; ++p )
{
tr_block_index_t i;
uint16_t completeBlocksInPiece = 0;
const tr_block_index_t start = tr_torPieceFirstBlock( tor, p );
const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, p );
for( i=start; i!=end; ++i ) {
if( tr_bitfieldTestFast( blockBitfield, i ) ) {
++completeBlocksInPiece;
cp->sizeNow += tr_torBlockCountBytes( tor, i );
}
}
cp->completeBlocks[p] = completeBlocksInPiece;
if( completeBlocksInPiece == end - start )
tr_bitfieldAdd( &cp->pieceBitfield, p );
}
memcpy( cp->blockBitfield->bits, blockBitfield->bits, cp->blockBitfield->byteCount );
cp->haveValidIsDirty = 1;
cp->sizeWhenDoneIsDirty = 1;
}
return success;
}
/*** /***
**** ****