mirror of
https://github.com/transmission/transmission
synced 2024-12-26 01:27:28 +00:00
(trunk libT) when filtering out peers that aren't candidates, use the fastest filter tests first, so that the more expensive tests will be applied to fewer peers. In particular, call peerIsInUse() last.
This commit is contained in:
parent
f0a70d77b6
commit
89201ab829
1 changed files with 12 additions and 10 deletions
|
@ -271,10 +271,12 @@ handshakeCompare( const void * a, const void * b )
|
|||
return handshakeCompareToAddr( a, tr_handshakeGetAddr( b, NULL ) );
|
||||
}
|
||||
|
||||
static tr_handshake*
|
||||
getExistingHandshake( tr_ptrArray * handshakes,
|
||||
const tr_address * addr )
|
||||
static inline tr_handshake*
|
||||
getExistingHandshake( tr_ptrArray * handshakes, const tr_address * addr )
|
||||
{
|
||||
if( tr_ptrArrayEmpty( handshakes ) )
|
||||
return NULL;
|
||||
|
||||
return tr_ptrArrayFindSorted( handshakes, addr, handshakeCompareToAddr );
|
||||
}
|
||||
|
||||
|
@ -566,7 +568,7 @@ atomSetSeed( struct peer_atom * atom )
|
|||
atomSetSeedProbability( atom, 100 );
|
||||
}
|
||||
|
||||
static tr_bool
|
||||
static inline tr_bool
|
||||
atomIsSeed( const struct peer_atom * atom )
|
||||
{
|
||||
return atom->seedProbability == 100;
|
||||
|
@ -3244,10 +3246,6 @@ isBandwidthMaxedOut( const tr_bandwidth * b,
|
|||
static tr_bool
|
||||
isPeerCandidate( const tr_torrent * tor, const struct peer_atom * atom, const time_t now )
|
||||
{
|
||||
/* not if we've already got a connection to them... */
|
||||
if( peerIsInUse( tor->torrentPeers, atom ) )
|
||||
return FALSE;
|
||||
|
||||
/* not if they're banned... */
|
||||
if( atom->myflags & MYFLAG_BANNED )
|
||||
return FALSE;
|
||||
|
@ -3266,6 +3264,10 @@ isPeerCandidate( const tr_torrent * tor, const struct peer_atom * atom, const ti
|
|||
if( tr_sessionIsAddressBlocked( tor->session, &atom->addr ) )
|
||||
return FALSE;
|
||||
|
||||
/* not if we've already got a connection to them... */
|
||||
if( peerIsInUse( tor->torrentPeers, atom ) )
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
@ -3342,8 +3344,8 @@ comparePeerCandidates( const void * va, const void * vb )
|
|||
const struct peer_candidate * a = va;
|
||||
const struct peer_candidate * b = vb;
|
||||
|
||||
if( a->score != b->score )
|
||||
return a->score < b->score ? -1 : 1;
|
||||
if( a->score < b->score ) return -1;
|
||||
if( a->score > b->score ) return 1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue