Changeset 9611


Ignore:
Timestamp:
Nov 28, 2009, 7:15:31 AM (12 years ago)
Author:
charles
Message:

(trunk libT) performance improvements to peer-mgr.c's peerIsInUse()

File:
1 edited

Legend:

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

    r9600 r9611  
    115115struct peer_atom
    116116{
     117    tr_peer   * peer;        /* will be NULL if not connected */
    117118    uint8_t     from;
    118119    uint8_t     flags;       /* these match the added_f flags */
     
    310311}
    311312
    312 static int
    313 peerCompareToAddr( const void * a, const void * vb )
    314 {
    315     return tr_compareAddresses( tr_peerAddress( a ), vb );
    316 }
    317 
    318 static tr_peer*
    319 getExistingPeer( Torrent          * torrent,
    320                  const tr_address * addr )
    321 {
    322     assert( torrentIsLocked( torrent ) );
    323     assert( addr );
    324 
    325     return tr_ptrArrayFindSorted( &torrent->peers, addr, peerCompareToAddr );
    326 }
    327 
    328313static struct peer_atom*
    329314getExistingAtom( const Torrent    * t,
     
    336321
    337322static tr_bool
    338 peerIsInUse( const Torrent    * ct,
    339              const tr_address * addr )
     323peerIsInUse( const Torrent * ct, const struct peer_atom * atom )
    340324{
    341325    Torrent * t = (Torrent*) ct;
     
    343327    assert( torrentIsLocked ( t ) );
    344328
    345     return getExistingPeer( t, addr )
    346         || getExistingHandshake( &t->outgoingHandshakes, addr )
    347         || getExistingHandshake( &t->manager->incomingHandshakes, addr );
     329    return ( atom->peer != NULL )
     330        || getExistingHandshake( &t->outgoingHandshakes, &atom->addr )
     331        || getExistingHandshake( &t->manager->incomingHandshakes, &atom->addr );
    348332}
    349333
     
    354338    tr_bitsetConstructor( &peer->have, 0 );
    355339    peer->atom = atom;
     340    atom->peer = peer;
     341    peer->atom = atom;
    356342    return peer;
    357343}
     
    364350    assert( torrentIsLocked( torrent ) );
    365351
    366     peer = getExistingPeer( torrent, &atom->addr );
     352    peer = atom->peer;
    367353
    368354    if( peer == NULL )
     
    396382    tr_bitfieldFree( peer->blame );
    397383    tr_free( peer->client );
     384    peer->atom->peer = NULL;
    398385
    399386    tr_free( peer );
     
    15181505        else
    15191506        {
    1520             tr_peer * peer = getExistingPeer( t, addr );
     1507            tr_peer * peer = atom->peer;
    15211508
    15221509            if( peer ) /* we already have this peer */
     
    25392526
    25402527        /* we don't need two connections to the same peer... */
    2541         if( peerIsInUse( t, &atom->addr ) )
     2528        if( peerIsInUse( t, atom ) )
    25422529            continue;
    25432530
     
    30263013            for( i=0; i<atomCount; ++i ) {
    30273014                struct peer_atom * atom = atoms[i];
    3028                 if( peerIsInUse( t, &atom->addr ) )
     3015                if( peerIsInUse( t, atom ) )
    30293016                    keep[keepCount++] = atom;
    30303017                else
Note: See TracChangeset for help on using the changeset viewer.