From 1499f5c405dbb2fcd917b94013bcb01de0e14c14 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Mon, 22 Feb 2010 15:07:14 +0000 Subject: [PATCH] (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 --- libtransmission/peer-mgr.c | 77 +++++--------------------------------- 1 file changed, 9 insertions(+), 68 deletions(-) diff --git a/libtransmission/peer-mgr.c b/libtransmission/peer-mgr.c index ea0666d2c..1b0bcf6ca 100644 --- a/libtransmission/peer-mgr.c +++ b/libtransmission/peer-mgr.c @@ -173,7 +173,6 @@ typedef struct tr_torrent_peers tr_bool needsCompletenessCheck; struct block_request * requests; - int requestsSort; int requestCount; int requestAlloc; @@ -554,13 +553,6 @@ tr_peerMgrPeerIsSeed( const tr_torrent * tor, *** struct block_request **/ -enum -{ - REQ_UNSORTED, - REQ_SORTED_BY_BLOCK, - REQ_SORTED_BY_TIME -}; - static int compareReqByBlock( const void * va, const void * vb ) { @@ -578,45 +570,6 @@ compareReqByBlock( const void * va, const void * vb ) return 0; } -static int -compareReqByTime( const void * va, const void * vb ) -{ - const struct block_request * a = va; - const struct block_request * b = vb; - - /* primary key: time */ - if( a->sentAt < b->sentAt ) return -1; - if( a->sentAt > b->sentAt ) return 1; - - /* secondary key: peer */ - if( a->peer < b->peer ) return -1; - if( a->peer > b->peer ) return 1; - - return 0; -} - -static void -requestListSort( Torrent * t, int mode ) -{ - assert( mode==REQ_SORTED_BY_BLOCK || mode==REQ_SORTED_BY_TIME ); - - if( t->requestsSort != mode ) - { - int(*compar)(const void *, const void *); - - t->requestsSort = mode; - - switch( mode ) { - case REQ_SORTED_BY_BLOCK: compar = compareReqByBlock; break; - case REQ_SORTED_BY_TIME: compar = compareReqByTime; break; - default: assert( 0 && "unhandled" ); - } - - qsort( t->requests, t->requestCount, - sizeof( struct block_request ), compar ); - } -} - static void requestListAdd( Torrent * t, tr_block_index_t block, tr_peer * peer ) { @@ -637,25 +590,16 @@ requestListAdd( Torrent * t, tr_block_index_t block, tr_peer * peer ) key.sentAt = tr_time( ); /* insert the request to our array... */ - switch( t->requestsSort ) { - case REQ_UNSORTED: - case REQ_SORTED_BY_TIME: - t->requests[t->requestCount++] = key; - break; - - case REQ_SORTED_BY_BLOCK: { - tr_bool exact; - const int pos = tr_lowerBound( &key, t->requests, t->requestCount, - sizeof( struct block_request ), - compareReqByBlock, &exact ); - assert( !exact ); - memmove( t->requests + pos + 1, - t->requests + pos, - sizeof( struct block_request ) * ( t->requestCount++ - pos ) ); - t->requests[pos] = key; - break; - } + tr_bool exact; + const int pos = tr_lowerBound( &key, t->requests, t->requestCount, + sizeof( struct block_request ), + compareReqByBlock, &exact ); + assert( !exact ); + memmove( t->requests + pos + 1, + t->requests + pos, + sizeof( struct block_request ) * ( t->requestCount++ - pos ) ); + t->requests[pos] = key; } if( peer != NULL ) @@ -676,8 +620,6 @@ requestListLookup( Torrent * t, tr_block_index_t block, const tr_peer * peer ) key.block = block; key.peer = (tr_peer*) peer; - requestListSort( t, REQ_SORTED_BY_BLOCK ); - return bsearch( &key, t->requests, t->requestCount, sizeof( struct block_request ), compareReqByBlock ); @@ -691,7 +633,6 @@ countBlockRequests( Torrent * t, tr_block_index_t block ) int i, n, pos; struct block_request key; - requestListSort( t, REQ_SORTED_BY_BLOCK ); key.block = block; key.peer = NULL; pos = tr_lowerBound( &key, t->requests, t->requestCount,