Changeset 10270


Ignore:
Timestamp:
Feb 22, 2010, 3:07:14 PM (12 years ago)
Author:
charles
Message:

(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92(trunk libT) #2906 "remove unused code: Torrent.requests array is never sorted by time" -- added to trunk for 1.92

File:
1 edited

Legend:

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

    r10238 r10270  
    174174
    175175    struct block_request     * requests;
    176     int                        requestsSort;
    177176    int                        requestCount;
    178177    int                        requestAlloc;
     
    555554**/
    556555
    557 enum
    558 {
    559     REQ_UNSORTED,
    560     REQ_SORTED_BY_BLOCK,
    561     REQ_SORTED_BY_TIME
    562 };
    563 
    564556static int
    565557compareReqByBlock( const void * va, const void * vb )
     
    577569
    578570    return 0;
    579 }
    580 
    581 static int
    582 compareReqByTime( const void * va, const void * vb )
    583 {
    584     const struct block_request * a = va;
    585     const struct block_request * b = vb;
    586 
    587     /* primary key: time */
    588     if( a->sentAt < b->sentAt ) return -1;
    589     if( a->sentAt > b->sentAt ) return 1;
    590 
    591     /* secondary key: peer */
    592     if( a->peer < b->peer ) return -1;
    593     if( a->peer > b->peer ) return 1;
    594 
    595     return 0;
    596 }
    597 
    598 static void
    599 requestListSort( Torrent * t, int mode )
    600 {
    601     assert( mode==REQ_SORTED_BY_BLOCK || mode==REQ_SORTED_BY_TIME );
    602 
    603     if( t->requestsSort != mode )
    604     {
    605         int(*compar)(const void *, const void *);
    606 
    607         t->requestsSort = mode;
    608 
    609         switch( mode ) {
    610             case REQ_SORTED_BY_BLOCK: compar = compareReqByBlock; break;
    611             case REQ_SORTED_BY_TIME: compar = compareReqByTime; break;
    612             default: assert( 0 && "unhandled" );
    613         }
    614 
    615         qsort( t->requests, t->requestCount,
    616                sizeof( struct block_request ), compar );
    617     }
    618571}
    619572
     
    638591
    639592    /* insert the request to our array... */
    640     switch( t->requestsSort )
    641     {
    642         case REQ_UNSORTED:
    643         case REQ_SORTED_BY_TIME:
    644             t->requests[t->requestCount++] = key;
    645             break;
    646 
    647         case REQ_SORTED_BY_BLOCK: {
    648             tr_bool exact;
    649             const int pos = tr_lowerBound( &key, t->requests, t->requestCount,
    650                                            sizeof( struct block_request ),
    651                                            compareReqByBlock, &exact );
    652             assert( !exact );
    653             memmove( t->requests + pos + 1,
    654                      t->requests + pos,
    655                      sizeof( struct block_request ) * ( t->requestCount++ - pos ) );
    656             t->requests[pos] = key;
    657             break;
    658         }
     593    {
     594        tr_bool exact;
     595        const int pos = tr_lowerBound( &key, t->requests, t->requestCount,
     596                                       sizeof( struct block_request ),
     597                                       compareReqByBlock, &exact );
     598        assert( !exact );
     599        memmove( t->requests + pos + 1,
     600                 t->requests + pos,
     601                 sizeof( struct block_request ) * ( t->requestCount++ - pos ) );
     602        t->requests[pos] = key;
    659603    }
    660604
     
    677621    key.peer = (tr_peer*) peer;
    678622
    679     requestListSort( t, REQ_SORTED_BY_BLOCK );
    680 
    681623    return bsearch( &key, t->requests, t->requestCount,
    682624                    sizeof( struct block_request ),
     
    692634    struct block_request key;
    693635
    694     requestListSort( t, REQ_SORTED_BY_BLOCK );
    695636    key.block = block;
    696637    key.peer = NULL;
Note: See TracChangeset for help on using the changeset viewer.