From 3c3fda5c66ed3a32e89832505ef0f111237630d8 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Mon, 9 May 2011 04:16:49 +0000 Subject: [PATCH] (trunk libT) CPU optimization in tr_bandwidthClamp(). Don't call tr_time_msec() if it's not necessary. This was one of the top CPU sinks in profiling, so removing it is a nice improvement in cases when it's not necessary, such as when speed limiting is disabled. --- libtransmission/bandwidth.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/libtransmission/bandwidth.c b/libtransmission/bandwidth.c index c728fcf73..b9bb0125f 100644 --- a/libtransmission/bandwidth.c +++ b/libtransmission/bandwidth.c @@ -322,7 +322,7 @@ tr_bandwidthSetPeer( tr_bandwidth * b, tr_peerIo * peer ) static unsigned int bandwidthClamp( const tr_bandwidth * b, - const uint64_t now, + uint64_t now, tr_direction dir, unsigned int byteCount ) { @@ -339,9 +339,16 @@ bandwidthClamp( const tr_bandwidth * b, * clamp down harder on the bytes available */ if( byteCount > 0 ) { - double current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN ); - double desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN ); - double r = desired >= 1 ? current / desired : 0; + double current; + double desired; + double r; + + if( now == 0 ) + now = tr_time_msec( ); + + current = tr_bandwidthGetRawSpeed_Bps( b, now, TR_DOWN ); + desired = tr_bandwidthGetDesiredSpeed_Bps( b, TR_DOWN ); + r = desired >= 1 ? current / desired : 0; if( r > 1.0 ) byteCount = 0; else if( r > 0.9 ) byteCount *= 0.8; @@ -360,8 +367,7 @@ tr_bandwidthClamp( const tr_bandwidth * b, tr_direction dir, unsigned int byteCount ) { - const uint64_t now_msec = tr_time_msec( ); - return bandwidthClamp( b, now_msec, dir, byteCount ); + return bandwidthClamp( b, 0, dir, byteCount ); } -- 2.40.0