mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
(libT) make tr_torrentAvailability() a lot faster in the case where the torrent is complete, and a little faster in the genral case too.
This commit is contained in:
parent
52cd591d5c
commit
51f1126a6d
1 changed files with 8 additions and 4 deletions
|
@ -1286,12 +1286,17 @@ tr_peerMgrTorrentAvailability( const tr_peerMgr * manager,
|
||||||
const Torrent * t;
|
const Torrent * t;
|
||||||
const tr_torrent * tor;
|
const tr_torrent * tor;
|
||||||
float interval;
|
float interval;
|
||||||
|
int isComplete;
|
||||||
|
int peerCount;
|
||||||
|
const tr_peer ** peers;
|
||||||
|
|
||||||
managerLock( (tr_peerMgr*)manager );
|
managerLock( (tr_peerMgr*)manager );
|
||||||
|
|
||||||
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
|
||||||
tor = t->tor;
|
tor = t->tor;
|
||||||
interval = tor->info.pieceCount / (float)tabCount;
|
interval = tor->info.pieceCount / (float)tabCount;
|
||||||
|
isComplete = tor && ( tr_cpGetStatus ( tor->completion ) == TR_CP_COMPLETE );
|
||||||
|
peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
|
||||||
|
|
||||||
memset( tab, 0, tabCount );
|
memset( tab, 0, tabCount );
|
||||||
|
|
||||||
|
@ -1301,11 +1306,10 @@ tr_peerMgrTorrentAvailability( const tr_peerMgr * manager,
|
||||||
|
|
||||||
if( tor == NULL )
|
if( tor == NULL )
|
||||||
tab[i] = 0;
|
tab[i] = 0;
|
||||||
else if( tr_cpPieceIsComplete( tor->completion, piece ) )
|
else if( isComplete || tr_cpPieceIsComplete( tor->completion, piece ) )
|
||||||
tab[i] = -1;
|
tab[i] = -1;
|
||||||
else {
|
else if( peerCount ) {
|
||||||
int j, peerCount;
|
int j;
|
||||||
const tr_peer ** peers = (const tr_peer **) tr_ptrArrayPeek( t->peers, &peerCount );
|
|
||||||
for( j=0; j<peerCount; ++j )
|
for( j=0; j<peerCount; ++j )
|
||||||
if( tr_bitfieldHas( peers[j]->have, i ) )
|
if( tr_bitfieldHas( peers[j]->have, i ) )
|
||||||
++tab[i];
|
++tab[i];
|
||||||
|
|
Loading…
Reference in a new issue