1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-25 17:17:31 +00:00

(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

This commit is contained in:
Charles Kerr 2010-02-22 15:07:14 +00:00
parent 5b029c68cd
commit 1499f5c405

View file

@ -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,