Changeset 12421


Ignore:
Timestamp:
May 10, 2011, 1:51:12 AM (10 years ago)
Author:
jordan
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/peer-mgr.c

    r12402 r12421  
    38093809getPeerCandidates( tr_session * session, int * candidateCount )
    38103810{
    3811     int n;
     3811    int atomCount;
     3812    int peerCount;
    38123813    tr_torrent * tor;
    38133814    struct peer_candidate * candidates;
     
    38183819    const int maxCandidates = tr_sessionGetPeerLimit( session ) * 0.95;
    38193820
     3821    /* count how many peers and atoms we've got */
     3822    tor= NULL;
     3823    atomCount = 0;
     3824    peerCount = 0;
     3825    while(( tor = tr_torrentNext( session, tor ))) {
     3826        atomCount += tr_ptrArraySize( &tor->torrentPeers->pool );
     3827        peerCount += tr_ptrArraySize( &tor->torrentPeers->peers );
     3828    }
     3829
    38203830    /* don't start any new handshakes if we're full up */
    3821     n = 0;
    3822     tor= NULL;
    3823     while(( tor = tr_torrentNext( session, tor )))
    3824         n += tr_ptrArraySize( &tor->torrentPeers->peers );
    3825     if( maxCandidates <= n ) {
     3831    if( maxCandidates <= peerCount ) {
    38263832        *candidateCount = 0;
    38273833        return NULL;
     
    38293835
    38303836    /* allocate an array of candidates */
    3831     n = 0;
    3832     tor= NULL;
    3833     while(( tor = tr_torrentNext( session, tor )))
    3834         n += tr_ptrArraySize( &tor->torrentPeers->pool );
    3835     walk = candidates = tr_new( struct peer_candidate, n );
     3837    walk = candidates = tr_new( struct peer_candidate, atomCount );
    38363838
    38373839    /* populate the candidate array */
Note: See TracChangeset for help on using the changeset viewer.