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:
parent
56d56a2e19
commit
c0e1cd8007
1 changed files with 17 additions and 11 deletions
|
@ -463,10 +463,12 @@ addPeers( const tr_torrent * tor,
|
||||||
#define tr_streq(a,alen,b) ((alen+1==sizeof(b)) && !memcmp(a,b,alen))
|
#define tr_streq(a,alen,b) ((alen+1==sizeof(b)) && !memcmp(a,b,alen))
|
||||||
|
|
||||||
static void
|
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 );
|
const size_t keylen = strlen( key );
|
||||||
|
|
||||||
if( tr_streq( key, keylen, "activityDate" ) )
|
if( tr_streq( key, keylen, "activityDate" ) )
|
||||||
|
@ -634,19 +636,23 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
addInfo( const tr_torrent * tor,
|
addInfo( const tr_torrent * tor, tr_benc * d, tr_benc * fields )
|
||||||
tr_benc * d,
|
|
||||||
tr_benc * fields )
|
|
||||||
{
|
{
|
||||||
int i;
|
|
||||||
const int n = tr_bencListSize( fields );
|
|
||||||
const char * str;
|
const char * str;
|
||||||
|
const int n = tr_bencListSize( fields );
|
||||||
|
|
||||||
tr_bencInitDict( d, n );
|
tr_bencInitDict( d, n );
|
||||||
|
|
||||||
for( i = 0; i < n; ++i )
|
if( n > 0 )
|
||||||
if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) )
|
{
|
||||||
addField( tor, d, str );
|
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, inf, st, d, str );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static const char*
|
static const char*
|
||||||
|
|
Loading…
Reference in a new issue