Changeset 12419


Ignore:
Timestamp:
May 9, 2011, 4:13:14 AM (10 years ago)
Author:
jordan
Message:

(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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpcimpl.c

    r12391 r12419  
    464464
    465465static void
    466 addField( const tr_torrent * tor, tr_benc * d, const char * key )
    467 {
    468     const tr_info * inf = tr_torrentInfo( tor );
    469     const tr_stat * st = tr_torrentStat( (tr_torrent*)tor );
     466addField( const tr_torrent * const tor,
     467          const tr_info    * const inf,
     468          const tr_stat    * const st,
     469          tr_benc          * const d,
     470          const char       * const key )
     471{
    470472    const size_t keylen = strlen( key );
    471473
     
    635637
    636638static void
    637 addInfo( const tr_torrent * tor,
    638          tr_benc *          d,
    639          tr_benc *          fields )
    640 {
    641     int          i;
    642     const int    n = tr_bencListSize( fields );
     639addInfo( const tr_torrent * tor, tr_benc * d, tr_benc * fields )
     640{
    643641    const char * str;
     642    const int n = tr_bencListSize( fields );
    644643
    645644    tr_bencInitDict( d, n );
    646645
    647     for( i = 0; i < n; ++i )
    648         if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) )
    649             addField( tor, d, str );
     646    if( n > 0 )
     647    {
     648        int i;
     649        const tr_info const * inf = tr_torrentInfo( tor );
     650        const tr_stat const * st = tr_torrentStat( (tr_torrent*)tor );
     651
     652        for( i=0; i<n; ++i )
     653            if( tr_bencGetStr( tr_bencListChild( fields, i ), &str ) )
     654                addField( tor, inf, st, d, str );
     655    }
    650656}
    651657
Note: See TracChangeset for help on using the changeset viewer.