mirror of
https://github.com/transmission/transmission
synced 2024-12-23 08:13:27 +00:00
(trunk libT) speedups to comparePeerCandidates()
This commit is contained in:
parent
8b23681730
commit
a33be6c4b8
1 changed files with 9 additions and 9 deletions
|
@ -3274,6 +3274,8 @@ struct peer_candidate
|
||||||
int salt;
|
int salt;
|
||||||
tr_torrent * tor;
|
tr_torrent * tor;
|
||||||
struct peer_atom * atom;
|
struct peer_atom * atom;
|
||||||
|
tr_priority_t priority;
|
||||||
|
tr_bool wasRecentlyStarted;
|
||||||
};
|
};
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
@ -3299,7 +3301,7 @@ torrentWasRecentlyStarted( const tr_torrent * tor )
|
||||||
static int
|
static int
|
||||||
comparePeerCandidates( const void * va, const void * vb )
|
comparePeerCandidates( const void * va, const void * vb )
|
||||||
{
|
{
|
||||||
int i, ai, bi;
|
int i;
|
||||||
tr_bool af, bf;
|
tr_bool af, bf;
|
||||||
const struct peer_candidate * a = va;
|
const struct peer_candidate * a = va;
|
||||||
const struct peer_candidate * b = vb;
|
const struct peer_candidate * b = vb;
|
||||||
|
@ -3315,16 +3317,12 @@ comparePeerCandidates( const void * va, const void * vb )
|
||||||
return a->atom->lastConnectionAttemptAt < b->atom->lastConnectionAttemptAt ? -1 : 1;
|
return a->atom->lastConnectionAttemptAt < b->atom->lastConnectionAttemptAt ? -1 : 1;
|
||||||
|
|
||||||
/* prefer peers belonging to a torrent of a higher priority */
|
/* prefer peers belonging to a torrent of a higher priority */
|
||||||
ai = tr_torrentGetPriority( a->tor );
|
if( a->priority != b->priority )
|
||||||
bi = tr_torrentGetPriority( b->tor );
|
return a->priority > b->priority ? -1 : 1;
|
||||||
if( ai != bi )
|
|
||||||
return ai > bi ? -1 : 1;
|
|
||||||
|
|
||||||
/* prefer recently-started torrents */
|
/* prefer recently-started torrents */
|
||||||
af = torrentWasRecentlyStarted( a->tor );
|
if( a->wasRecentlyStarted != b->wasRecentlyStarted )
|
||||||
bf = torrentWasRecentlyStarted( a->tor );
|
return a->wasRecentlyStarted ? -1 : 1;
|
||||||
if( af != bf )
|
|
||||||
return af ? -1 : 1;
|
|
||||||
|
|
||||||
/* prefer peers that we might have a chance of uploading to */
|
/* prefer peers that we might have a chance of uploading to */
|
||||||
if(( i = compareSeedProbabilities( a->atom->seedProbability, b->atom->seedProbability )))
|
if(( i = compareSeedProbabilities( a->atom->seedProbability, b->atom->seedProbability )))
|
||||||
|
@ -3396,6 +3394,8 @@ getPeerCandidates( tr_session * session, int * candidateCount )
|
||||||
walk->tor = tor;
|
walk->tor = tor;
|
||||||
walk->atom = atom;
|
walk->atom = atom;
|
||||||
walk->salt = tr_cryptoWeakRandInt( 4096 );
|
walk->salt = tr_cryptoWeakRandInt( 4096 );
|
||||||
|
walk->priority = tr_torrentGetPriority( tor );
|
||||||
|
walk->wasRecentlyStarted = torrentWasRecentlyStarted( tor );
|
||||||
++walk;
|
++walk;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue