1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 17:47:37 +00:00

(trunk libT) torrent-get CPU optimization.

Move the tr_torrentStat() call outside of the addField() loop so that it's only called once instead of N times.
This commit is contained in:
Jordan Lee 2011-05-09 04:13:14 +00:00
parent 56d56a2e19
commit c0e1cd8007

View file

@ -463,10 +463,12 @@ addPeers( const tr_torrent * tor,
#define tr_streq(a,alen,b) ((alen+1==sizeof(b)) && !memcmp(a,b,alen))
static void
addField( const tr_torrent * tor, tr_benc * d, const char * key )
addField( const tr_torrent * const tor,
const tr_info * const inf,
const tr_stat * const st,
tr_benc * const d,
const char * const key )
{
const tr_info * inf = tr_torrentInfo( tor );
const tr_stat * st = tr_torrentStat( (tr_torrent*)tor );
const size_t keylen = strlen( key );
if( tr_streq( key, keylen, "activityDate" ) )
@ -634,19 +636,23 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
}
static void
addInfo( const tr_torrent * tor,
tr_benc * d,
tr_benc * fields )
addInfo( const tr_torrent * tor, tr_benc * d, tr_benc * fields )
{
int i;
const int n = tr_bencListSize( fields );
const char * str;
const int n = tr_bencListSize( fields );
tr_bencInitDict( d, n );
for( i = 0; i < n; ++i )
if( n > 0 )
{
int i;
const tr_info const * inf = tr_torrentInfo( tor );
const tr_stat const * st = tr_torrentStat( (tr_torrent*)tor );
for( i=0; i<n; ++i )
if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) )
addField( tor, d, str );
addField( tor, inf, st, d, str );
}
}
static const char*