From eb24ad760df81790f1279b0ae200e2fcc0766c85 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Tue, 1 Apr 2008 02:35:04 +0000 Subject: [PATCH] (1) make tr_torrentRates() faster. (2) new function: tr_torrentGetStatus() for when you need the status but not the overhead of tr_stat --- libtransmission/torrent.c | 31 ++++++++++++++++++------------- libtransmission/transmission.c | 13 ++++--------- libtransmission/transmission.h | 2 ++ 3 files changed, 24 insertions(+), 22 deletions(-) diff --git a/libtransmission/torrent.c b/libtransmission/torrent.c index cfe7a6dfa..3f6140a88 100644 --- a/libtransmission/torrent.c +++ b/libtransmission/torrent.c @@ -558,6 +558,23 @@ tr_torrentStatCached( tr_torrent * tor ) : tr_torrentStat( tor ); } +tr_torrent_status +tr_torrentGetStatus( tr_torrent * tor ) +{ + tr_torrentRecheckCompleteness( tor ); + + if( tor->verifyState == TR_VERIFY_NOW ) + return TR_STATUS_CHECK; + if( tor->verifyState == TR_VERIFY_WAIT ) + return TR_STATUS_CHECK_WAIT; + if( !tor->isRunning ) + return TR_STATUS_STOPPED; + if( tor->cpStatus == TR_CP_INCOMPLETE ) + return TR_STATUS_DOWNLOAD; + + return TR_STATUS_SEED; +} + const tr_stat * tr_torrentStat( tr_torrent * tor ) { @@ -567,10 +584,9 @@ tr_torrentStat( tr_torrent * tor ) tr_torrentLock( tor ); tor->lastStatTime = time( NULL ); - tr_torrentRecheckCompleteness( tor ); s = &tor->stats; - + s->status = tr_torrentGetStatus( tor ); s->error = tor->error; memcpy( s->errorString, tor->errorString, sizeof( s->errorString ) ); @@ -595,17 +611,6 @@ tr_torrentStat( tr_torrent * tor ) s->percentDone = tr_cpPercentDone( tor->completion ); s->leftUntilDone = tr_cpLeftUntilDone( tor->completion ); - if( tor->verifyState == TR_VERIFY_NOW ) - s->status = TR_STATUS_CHECK; - else if( tor->verifyState == TR_VERIFY_WAIT ) - s->status = TR_STATUS_CHECK_WAIT; - else if( !tor->isRunning ) - s->status = TR_STATUS_STOPPED; - else if( tor->cpStatus == TR_CP_INCOMPLETE ) - s->status = TR_STATUS_DOWNLOAD; - else - s->status = TR_STATUS_SEED; - s->recheckProgress = 1.0 - (tr_torrentCountUncheckedPieces( tor ) / (double) tor->info.pieceCount); diff --git a/libtransmission/transmission.c b/libtransmission/transmission.c index c5b5b11f8..24953f6fc 100644 --- a/libtransmission/transmission.c +++ b/libtransmission/transmission.c @@ -347,17 +347,12 @@ tr_getGlobalPeerLimit( const tr_handle * handle UNUSED ) void tr_torrentRates( tr_handle * h, float * toClient, float * toPeer ) { - const tr_torrent * tor; tr_globalLock( h ); - *toClient = *toPeer = 0.0; - for( tor = h->torrentList; tor; tor = tor->next ) - { - float c, p; - tr_torrentGetRates( tor, &c, &p ); - *toClient += c; - *toPeer += p; - } + if( toClient ) + *toClient = tr_rcRate( h->download ); + if( toPeer ) + *toPeer = tr_rcRate( h->upload ); tr_globalUnlock( h ); } diff --git a/libtransmission/transmission.h b/libtransmission/transmission.h index 8c7bc7298..f0979a548 100644 --- a/libtransmission/transmission.h +++ b/libtransmission/transmission.h @@ -813,6 +813,8 @@ struct tr_tracker_stat time_t nextManualAnnounceTime; }; +tr_torrent_status tr_torrentGetStatus( tr_torrent * ); + struct tr_stat { tr_torrent_status status;