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:
parent
5b029c68cd
commit
1499f5c405
1 changed files with 9 additions and 68 deletions
|
@ -173,7 +173,6 @@ typedef struct tr_torrent_peers
|
||||||
tr_bool needsCompletenessCheck;
|
tr_bool needsCompletenessCheck;
|
||||||
|
|
||||||
struct block_request * requests;
|
struct block_request * requests;
|
||||||
int requestsSort;
|
|
||||||
int requestCount;
|
int requestCount;
|
||||||
int requestAlloc;
|
int requestAlloc;
|
||||||
|
|
||||||
|
@ -554,13 +553,6 @@ tr_peerMgrPeerIsSeed( const tr_torrent * tor,
|
||||||
*** struct block_request
|
*** struct block_request
|
||||||
**/
|
**/
|
||||||
|
|
||||||
enum
|
|
||||||
{
|
|
||||||
REQ_UNSORTED,
|
|
||||||
REQ_SORTED_BY_BLOCK,
|
|
||||||
REQ_SORTED_BY_TIME
|
|
||||||
};
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
compareReqByBlock( const void * va, const void * vb )
|
compareReqByBlock( const void * va, const void * vb )
|
||||||
{
|
{
|
||||||
|
@ -578,45 +570,6 @@ compareReqByBlock( const void * va, const void * vb )
|
||||||
return 0;
|
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
|
static void
|
||||||
requestListAdd( Torrent * t, tr_block_index_t block, tr_peer * peer )
|
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( );
|
key.sentAt = tr_time( );
|
||||||
|
|
||||||
/* insert the request to our array... */
|
/* insert the request to our array... */
|
||||||
switch( t->requestsSort )
|
|
||||||
{
|
{
|
||||||
case REQ_UNSORTED:
|
tr_bool exact;
|
||||||
case REQ_SORTED_BY_TIME:
|
const int pos = tr_lowerBound( &key, t->requests, t->requestCount,
|
||||||
t->requests[t->requestCount++] = key;
|
sizeof( struct block_request ),
|
||||||
break;
|
compareReqByBlock, &exact );
|
||||||
|
assert( !exact );
|
||||||
case REQ_SORTED_BY_BLOCK: {
|
memmove( t->requests + pos + 1,
|
||||||
tr_bool exact;
|
t->requests + pos,
|
||||||
const int pos = tr_lowerBound( &key, t->requests, t->requestCount,
|
sizeof( struct block_request ) * ( t->requestCount++ - pos ) );
|
||||||
sizeof( struct block_request ),
|
t->requests[pos] = key;
|
||||||
compareReqByBlock, &exact );
|
|
||||||
assert( !exact );
|
|
||||||
memmove( t->requests + pos + 1,
|
|
||||||
t->requests + pos,
|
|
||||||
sizeof( struct block_request ) * ( t->requestCount++ - pos ) );
|
|
||||||
t->requests[pos] = key;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if( peer != NULL )
|
if( peer != NULL )
|
||||||
|
@ -676,8 +620,6 @@ requestListLookup( Torrent * t, tr_block_index_t block, const tr_peer * peer )
|
||||||
key.block = block;
|
key.block = block;
|
||||||
key.peer = (tr_peer*) peer;
|
key.peer = (tr_peer*) peer;
|
||||||
|
|
||||||
requestListSort( t, REQ_SORTED_BY_BLOCK );
|
|
||||||
|
|
||||||
return bsearch( &key, t->requests, t->requestCount,
|
return bsearch( &key, t->requests, t->requestCount,
|
||||||
sizeof( struct block_request ),
|
sizeof( struct block_request ),
|
||||||
compareReqByBlock );
|
compareReqByBlock );
|
||||||
|
@ -691,7 +633,6 @@ countBlockRequests( Torrent * t, tr_block_index_t block )
|
||||||
int i, n, pos;
|
int i, n, pos;
|
||||||
struct block_request key;
|
struct block_request key;
|
||||||
|
|
||||||
requestListSort( t, REQ_SORTED_BY_BLOCK );
|
|
||||||
key.block = block;
|
key.block = block;
|
||||||
key.peer = NULL;
|
key.peer = NULL;
|
||||||
pos = tr_lowerBound( &key, t->requests, t->requestCount,
|
pos = tr_lowerBound( &key, t->requests, t->requestCount,
|
||||||
|
|
Loading…
Reference in a new issue