Changeset 7589


Ignore:
Timestamp:
Jan 2, 2009, 11:48:51 PM (12 years ago)
Author:
charles
Message:

(trunk libT) avoid unnecessary duplicate calls to tr_date() in tr_bandwidthUsed()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7587 r7589  
    5555
    5656static void
    57 bytesUsed( struct bratecontrol * r, size_t size )
    58 {
    59     const uint64_t now = tr_date ( );
    60 
     57bytesUsed( const uint64_t now, struct bratecontrol * r, size_t size )
     58{
    6159    if( r->transfers[r->newest].date + GRANULARITY_MSEC >= now )
    6260        r->transfers[r->newest].size += size;
     
    303301}
    304302
     303static void
     304bandwidthUsedImpl( tr_bandwidth  * b,
     305                   tr_direction    dir,
     306                   size_t          byteCount,
     307                   tr_bool         isPieceData,
     308                   uint64_t        now )
     309{
     310    struct tr_band * band;
     311    size_t oldBytesLeft;
     312
     313    assert( tr_isBandwidth( b ) );
     314    assert( tr_isDirection( dir ) );
     315
     316    band = &b->band[dir];
     317
     318    oldBytesLeft = band->bytesLeft;
     319
     320    if( band->isLimited && isPieceData )
     321        band->bytesLeft -= MIN( band->bytesLeft, byteCount );
     322
     323#ifdef DEBUG_DIRECTION
     324if( ( dir == DEBUG_DIRECTION ) && ( band->isLimited ) )
     325fprintf( stderr, "%p consumed %5zu bytes of %5s data... was %6zu, now %6zu left\n",
     326         b, byteCount, (isPieceData?"piece":"raw"), oldBytesLeft, band->bytesLeft );
     327#endif
     328
     329    bytesUsed( now, &band->raw, byteCount );
     330
     331    if( isPieceData )
     332        bytesUsed( now, &band->piece, byteCount );
     333
     334    if( b->parent != NULL )
     335        bandwidthUsedImpl( b->parent, dir, byteCount, isPieceData, now );
     336}
     337
    305338void
    306339tr_bandwidthUsed( tr_bandwidth  * b,
     
    309342                  tr_bool         isPieceData )
    310343{
    311     struct tr_band * band;
    312     size_t oldBytesLeft;
    313 
    314     assert( tr_isBandwidth( b ) );
    315     assert( tr_isDirection( dir ) );
    316 
    317     band = &b->band[dir];
    318 
    319     oldBytesLeft = band->bytesLeft;
    320 
    321     if( band->isLimited && isPieceData )
    322         band->bytesLeft -= MIN( band->bytesLeft, byteCount );
    323 
    324 #ifdef DEBUG_DIRECTION
    325 if( ( dir == DEBUG_DIRECTION ) && ( band->isLimited ) )
    326 fprintf( stderr, "%p consumed %5zu bytes of %5s data... was %6zu, now %6zu left\n",
    327          b, byteCount, (isPieceData?"piece":"raw"), oldBytesLeft, band->bytesLeft );
    328 #endif
    329 
    330     bytesUsed( &band->raw, byteCount );
    331 
    332     if( isPieceData )
    333         bytesUsed( &band->piece, byteCount );
    334 
    335     if( b->parent != NULL )
    336         tr_bandwidthUsed( b->parent, dir, byteCount, isPieceData );
    337 }
     344    bandwidthUsedImpl( b, dir, byteCount, isPieceData, tr_date( ) );
     345}
Note: See TracChangeset for help on using the changeset viewer.