mirror of
https://github.com/transmission/transmission
synced 2024-12-27 01:57:52 +00:00
(trunk libT) CPU improvement in peer-mgr.c's getPeerCandidates()
getPeerCandiates() used to read through all the torrents to determine the global peer connections, and then again to determine the global peer candidates. Now this is done in one loop instead of two.
This commit is contained in:
parent
3c3fda5c66
commit
6a38a368d6
1 changed files with 13 additions and 11 deletions
|
@ -3808,7 +3808,8 @@ comparePeerCandidates( const void * va, const void * vb )
|
||||||
static struct peer_candidate*
|
static struct peer_candidate*
|
||||||
getPeerCandidates( tr_session * session, int * candidateCount )
|
getPeerCandidates( tr_session * session, int * candidateCount )
|
||||||
{
|
{
|
||||||
int n;
|
int atomCount;
|
||||||
|
int peerCount;
|
||||||
tr_torrent * tor;
|
tr_torrent * tor;
|
||||||
struct peer_candidate * candidates;
|
struct peer_candidate * candidates;
|
||||||
struct peer_candidate * walk;
|
struct peer_candidate * walk;
|
||||||
|
@ -3817,22 +3818,23 @@ getPeerCandidates( tr_session * session, int * candidateCount )
|
||||||
/* leave 5% of connection slots for incoming connections -- ticket #2609 */
|
/* leave 5% of connection slots for incoming connections -- ticket #2609 */
|
||||||
const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95;
|
const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95;
|
||||||
|
|
||||||
/* don't start any new handshakes if we're full up */
|
/* count how many peers and atoms we've got */
|
||||||
n = 0;
|
|
||||||
tor= NULL;
|
tor= NULL;
|
||||||
while(( tor = tr_torrentNext( session, tor )))
|
atomCount = 0;
|
||||||
n += tr_ptrArraySize( &tor->torrentPeers->peers );
|
peerCount = 0;
|
||||||
if( maxCandidates <= n ) {
|
while(( tor = tr_torrentNext( session, tor ))) {
|
||||||
|
atomCount += tr_ptrArraySize( &tor->torrentPeers->pool );
|
||||||
|
peerCount += tr_ptrArraySize( &tor->torrentPeers->peers );
|
||||||
|
}
|
||||||
|
|
||||||
|
/* don't start any new handshakes if we're full up */
|
||||||
|
if( maxCandidates <= peerCount ) {
|
||||||
*candidateCount = 0;
|
*candidateCount = 0;
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* allocate an array of candidates */
|
/* allocate an array of candidates */
|
||||||
n = 0;
|
walk = candidates = tr_new( struct peer_candidate, atomCount );
|
||||||
tor= NULL;
|
|
||||||
while(( tor = tr_torrentNext( session, tor )))
|
|
||||||
n += tr_ptrArraySize( &tor->torrentPeers->pool );
|
|
||||||
walk = candidates = tr_new( struct peer_candidate, n );
|
|
||||||
|
|
||||||
/* populate the candidate array */
|
/* populate the candidate array */
|
||||||
tor = NULL;
|
tor = NULL;
|
||||||
|
|
Loading…
Reference in a new issue