From 89201ab8295831cdca0544ac7e1b028a0c7f60c3 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 14 Jun 2010 11:57:46 +0000 Subject: [PATCH] (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. --- libtransmission/peer-mgr.c | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ede767ecd..2cba779da 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -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; }