mirror of
https://github.com/transmission/transmission
synced 2025-03-06 11:38:21 +00:00
* now that we've got a new function at the top of the CPU hog list, tweak it too.
* reduce large torrents' memory consumption in tr_completion_t.
This commit is contained in:
parent
cd9f44652b
commit
7cfafc5371
3 changed files with 12 additions and 19 deletions
|
@ -29,8 +29,8 @@ struct tr_completion_s
|
|||
{
|
||||
tr_torrent_t * tor;
|
||||
|
||||
/* number of peers from whom we've requested this block */
|
||||
uint8_t * blockDownloaders;
|
||||
/* true if a peer is requesting this block */
|
||||
tr_bitfield_t * blockRequested;
|
||||
|
||||
/* do we have this block? */
|
||||
tr_bitfield_t * blockBitfield;
|
||||
|
@ -54,7 +54,7 @@ tr_completion_t * tr_cpInit( tr_torrent_t * tor )
|
|||
cp = tr_new( tr_completion_t, 1 );
|
||||
cp->tor = tor;
|
||||
cp->blockBitfield = tr_bitfieldNew( tor->blockCount );
|
||||
cp->blockDownloaders = tr_new( uint8_t, tor->blockCount );
|
||||
cp->blockRequested = tr_bitfieldNew( tor->blockCount );
|
||||
cp->pieceBitfield = tr_bitfieldNew( tor->info.pieceCount );
|
||||
cp->completeBlocks = tr_new( uint16_t, tor->info.pieceCount );
|
||||
|
||||
|
@ -67,7 +67,7 @@ void tr_cpClose( tr_completion_t * cp )
|
|||
{
|
||||
tr_free( cp->completeBlocks );
|
||||
tr_bitfieldFree( cp->pieceBitfield );
|
||||
tr_free( cp->blockDownloaders );
|
||||
tr_bitfieldFree( cp->blockRequested );
|
||||
tr_bitfieldFree( cp->blockBitfield );
|
||||
tr_free( cp );
|
||||
}
|
||||
|
@ -76,9 +76,9 @@ void tr_cpReset( tr_completion_t * cp )
|
|||
{
|
||||
tr_torrent_t * tor = cp->tor;
|
||||
|
||||
tr_bitfieldClear( cp->blockBitfield );
|
||||
memset( cp->blockDownloaders, 0, tor->blockCount );
|
||||
tr_bitfieldClear( cp->pieceBitfield );
|
||||
tr_bitfieldClear( cp->blockBitfield );
|
||||
tr_bitfieldClear( cp->blockRequested );
|
||||
memset( cp->completeBlocks, 0, sizeof(uint16_t) * tor->info.pieceCount );
|
||||
|
||||
cp->doneDirty = TRUE;
|
||||
|
@ -194,12 +194,12 @@ void tr_cpPieceRem( tr_completion_t * cp, int piece )
|
|||
/* Blocks */
|
||||
void tr_cpDownloaderAdd( tr_completion_t * cp, int block )
|
||||
{
|
||||
++cp->blockDownloaders[block];
|
||||
tr_bitfieldAdd( cp->blockRequested, block );
|
||||
}
|
||||
|
||||
void tr_cpDownloaderRem( tr_completion_t * cp, int block )
|
||||
{
|
||||
--cp->blockDownloaders[block];
|
||||
tr_bitfieldRem( cp->blockRequested, block );
|
||||
}
|
||||
|
||||
int tr_cpBlockIsComplete( const tr_completion_t * cp, int block )
|
||||
|
@ -271,7 +271,7 @@ tr_cpMissingBlocksForPiece( const tr_completion_t * cp, int piece )
|
|||
|
||||
n = 0;
|
||||
for( i = start; i < end; ++i )
|
||||
if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
|
||||
if( !tr_cpBlockIsComplete( cp, i ) && !tr_bitfieldHas( cp->blockRequested, i ) )
|
||||
++n;
|
||||
|
||||
return n;
|
||||
|
@ -285,7 +285,7 @@ int tr_cpMissingBlockInPiece( const tr_completion_t * cp, int piece )
|
|||
const int end = start + tr_torPieceCountBlocks(tor,piece);
|
||||
|
||||
for( i = start; i < end; ++i )
|
||||
if( !tr_cpBlockIsComplete( cp, i ) && !cp->blockDownloaders[i] )
|
||||
if( !tr_cpBlockIsComplete( cp, i ) && !tr_bitfieldHas( cp->blockRequested, i ) )
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
|
|
|
@ -580,13 +580,6 @@ tr_bitfieldIsEmpty( const tr_bitfield_t * bitfield )
|
|||
#define BIN(nth) ((nth>>3))
|
||||
#define BIT(nth) (1<<(7-(nth%8)))
|
||||
|
||||
int
|
||||
tr_bitfieldHas( const tr_bitfield_t * bitfield,
|
||||
size_t nth )
|
||||
{
|
||||
return bitfield && (bitfield->bits[ BIN(nth) ] & BIT(nth) );
|
||||
}
|
||||
|
||||
void
|
||||
tr_bitfieldAdd( tr_bitfield_t * bitfield, size_t nth )
|
||||
{
|
||||
|
|
|
@ -139,12 +139,12 @@ void tr_bitfieldAddRange( tr_bitfield_t *, size_t begin, size_t end );
|
|||
void tr_bitfieldRemRange ( tr_bitfield_t*, size_t begin, size_t end );
|
||||
|
||||
int tr_bitfieldIsEmpty( const tr_bitfield_t* );
|
||||
int tr_bitfieldHas( const tr_bitfield_t *, size_t bit );
|
||||
size_t tr_bitfieldCountTrueBits( const tr_bitfield_t* );
|
||||
|
||||
tr_bitfield_t* tr_bitfieldNegate( tr_bitfield_t* );
|
||||
tr_bitfield_t* tr_bitfieldAnd( tr_bitfield_t*, const tr_bitfield_t* );
|
||||
|
||||
|
||||
#define tr_bitfieldHas(bitfield,nth) \
|
||||
( ( bitfield ) && ( (bitfield)->bits[(nth)>>3] & 128 >>( (nth) & 7 ) ) )
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Add table
Reference in a new issue