(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.
This commit is contained in:
Jordan Lee 2011-05-09 04:16:49 +00:00
parent c0e1cd8007
commit 3c3fda5c66
1 changed files with 12 additions and 6 deletions

View File

@ -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 );
}