if tr_torrentStat() is called again in the same second for a torrent, return the cached value.

This commit is contained in:
Charles Kerr 2007-12-19 02:44:21 +00:00
parent b498e720e6
commit e9ca72237f
2 changed files with 8 additions and 0 deletions

View File

@ -162,6 +162,7 @@ struct tr_torrent
tr_recheck_state recheckState;
time_t lastStatTime;
tr_stat stats[2];
tr_torrent * next;

View File

@ -713,6 +713,13 @@ tr_torrentStat( tr_torrent * tor )
{
tr_stat * s;
struct tr_tracker * tc;
const time_t now = time( NULL );
/* generating these stats is expensive --
* update a maximum of once per second */
if( tor->lastStatTime == now )
return &tor->stats[tor->statCur];
tor->lastStatTime = now;
tr_torrentLock( tor );