Ignore:
Timestamp:
Apr 6, 2011, 11:27:11 PM (11 years ago)
Author:
jordan
Message:

(trunk libT) more heap pruning: avoid four unnecessary malloc() + free() calls per tr_peer.

This commit also changes tr_recentHistory from being a general-purpose tool to being a little more hardcoded for the only purpose it's used, in tr_peerMgr. If its files (history.[ch]) don't find any other "customers" in libtransmission, eventually it should be demoted to being a private helper class inside of peer-mgr.c and have the history.[ch] files removed from the build.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/history.c

    r12177 r12328  
    2121tr_historyAdd( tr_recentHistory * h, time_t now, unsigned int n )
    2222{
    23     if( h->slices[h->newest].date + (time_t)h->precision >= now )
     23    if( h->slices[h->newest].date == now )
    2424        h->slices[h->newest].n += n;
    2525    else {
    26         if( ++h->newest == h->sliceCount ) h->newest = 0;
     26        if( ++h->newest == TR_RECENT_HISTORY_PERIOD_SEC ) h->newest = 0;
    2727        h->slices[h->newest].date = now;
    2828        h->slices[h->newest].n = n;
     
    4444        n += h->slices[i].n;
    4545
    46         if( --i == -1 ) i = h->sliceCount - 1; /* circular history */
     46        if( --i == -1 ) i = TR_RECENT_HISTORY_PERIOD_SEC - 1; /* circular history */
    4747        if( i == h->newest ) break; /* we've come all the way around */
    4848    }
     
    5050    return n;
    5151}
    52 
    53 void
    54 tr_historyConstruct( tr_recentHistory * h, unsigned int seconds, unsigned int precision )
    55 {
    56     memset( h, 0, sizeof( tr_recentHistory ) );
    57 
    58     assert( precision <= seconds );
    59 
    60     h->precision = precision;
    61     h->sliceCount = seconds / precision;
    62     h->slices = tr_new0( struct tr_history_slice, h->sliceCount );
    63 }
    64 
    65 void
    66 tr_historyDestruct( tr_recentHistory * h )
    67 {
    68     tr_free( h->slices );
    69 }
Note: See TracChangeset for help on using the changeset viewer.