Changeset 8693


Ignore:
Timestamp:
Jun 14, 2009, 10:19:19 PM (13 years ago)
Author:
charles
Message:

(trunk libT) avoid an extra per-torrent malloc/free by aggregating its tr_bandwidth into its struct

Location:
trunk/libtransmission
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.h

    r8561 r8693  
    1818#define TR_BANDWIDTH_H
    1919
     20#include <assert.h>
     21
    2022#include "transmission.h"
    2123#include "ptrarray.h"
     
    3537    HISTORY_MSEC = 2000,
    3638    INTERVAL_MSEC = HISTORY_MSEC,
    37     GRANULARITY_MSEC = 50,
     39    GRANULARITY_MSEC = 200,
    3840    HISTORY_SIZE = ( INTERVAL_MSEC / GRANULARITY_MSEC ),
    3941    MAGIC_NUMBER = 43143
     
    153155 */
    154156static TR_INLINE void tr_bandwidthSetDesiredSpeed( tr_bandwidth        * bandwidth,
    155                                                 tr_direction          dir,
    156                                                 double                desiredSpeed )
     157                                                   tr_direction          dir,
     158                                                   double                desiredSpeed )
    157159{
    158160    bandwidth->band[dir].desiredSpeed = desiredSpeed;
     
    239241 * in that particular case we want to ignore the global speed limit...
    240242 */
    241 static TR_INLINE void tr_bandwidthHonorParentLimits ( tr_bandwidth        * bandwidth,
    242                                                       tr_direction          direction,
    243                                                       tr_bool               isEnabled )
     243static TR_INLINE void
     244tr_bandwidthHonorParentLimits( tr_bandwidth  * bandwidth,
     245                               tr_direction    direction,
     246                               tr_bool         isEnabled )
    244247{
    245248    assert( tr_isBandwidth( bandwidth ) );
     
    249252}
    250253
    251 static TR_INLINE tr_bool tr_bandwidthAreParentLimitsHonored( tr_bandwidth  * bandwidth,
    252                                                              tr_direction    direction )
     254static TR_INLINE tr_bool
     255tr_bandwidthAreParentLimitsHonored( const tr_bandwidth  * bandwidth,
     256                                    tr_direction          direction )
    253257{
    254258    assert( tr_isBandwidth( bandwidth ) );
  • trunk/libtransmission/peer-mgr.c

    r8550 r8693  
    13151315                peer->io = tr_handshakeStealIO( handshake ); /* this steals its refcount too, which is
    13161316                                                                balanced by our unref in peerDestructor()  */
    1317                 tr_peerIoSetParent( peer->io, t->tor->bandwidth );
     1317                tr_peerIoSetParent( peer->io, &t->tor->bandwidth );
    13181318                tr_peerMsgsNew( t->tor, peer, peerCallbackFunc, t, &peer->msgsTag );
    13191319
  • trunk/libtransmission/torrent.c

    r8683 r8693  
    115115    assert( tr_isDirection( dir ) );
    116116
    117     tr_bandwidthSetDesiredSpeed( tor->bandwidth, dir, KiB_sec );
     117    tr_bandwidthSetDesiredSpeed( &tor->bandwidth, dir, KiB_sec );
    118118}
    119119
     
    124124    assert( tr_isDirection( dir ) );
    125125
    126     return tr_bandwidthGetDesiredSpeed( tor->bandwidth, dir );
     126    return tr_bandwidthGetDesiredSpeed( &tor->bandwidth, dir );
    127127}
    128128
     
    133133    assert( tr_isDirection( dir ) );
    134134
    135     tr_bandwidthSetLimited( tor->bandwidth, dir, do_use );
     135    tr_bandwidthSetLimited( &tor->bandwidth, dir, do_use );
    136136}
    137137
     
    142142    assert( tr_isDirection( dir ) );
    143143
    144     return tr_bandwidthIsLimited( tor->bandwidth, dir );
     144    return tr_bandwidthIsLimited( &tor->bandwidth, dir );
    145145}
    146146
     
    150150    assert( tr_isTorrent( tor ) );
    151151
    152     tr_bandwidthHonorParentLimits( tor->bandwidth, TR_UP, doUse );
    153     tr_bandwidthHonorParentLimits( tor->bandwidth, TR_DOWN, doUse );
     152    tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_UP, doUse );
     153    tr_bandwidthHonorParentLimits( &tor->bandwidth, TR_DOWN, doUse );
    154154}
    155155
     
    159159    assert( tr_isTorrent( tor ) );
    160160
    161     return tr_bandwidthAreParentLimitsHonored( tor->bandwidth, TR_UP );
     161    return tr_bandwidthAreParentLimitsHonored( &tor->bandwidth, TR_UP );
    162162}
    163163
     
    543543    randomizeTiers( info );
    544544
    545     tor->bandwidth = tr_bandwidthNew( session, session->bandwidth );
     545    tr_bandwidthConstruct( &tor->bandwidth, session, session->bandwidth );
    546546
    547547    tor->blockSize = getBlockSize( info->pieceSize );
     
    886886    d = tr_peerMgrGetWebseedSpeed( tor, now );
    887887    s->swarmSpeed         = tr_rcRate( &tor->swarmSpeed, now );
    888     s->rawUploadSpeed     = tr_bandwidthGetRawSpeed  ( tor->bandwidth, now, TR_UP );
    889     s->pieceUploadSpeed   = tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_UP );
    890     s->rawDownloadSpeed   = d + tr_bandwidthGetRawSpeed  ( tor->bandwidth, now, TR_DOWN );
    891     s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( tor->bandwidth, now, TR_DOWN );
     888    s->rawUploadSpeed     = tr_bandwidthGetRawSpeed  ( &tor->bandwidth, now, TR_UP );
     889    s->pieceUploadSpeed   = tr_bandwidthGetPieceSpeed( &tor->bandwidth, now, TR_UP );
     890    s->rawDownloadSpeed   = d + tr_bandwidthGetRawSpeed  ( &tor->bandwidth, now, TR_DOWN );
     891    s->pieceDownloadSpeed = d + tr_bandwidthGetPieceSpeed( &tor->bandwidth, now, TR_DOWN );
    892892
    893893    usableSeeds += tor->info.webseedCount;
     
    12111211    session->torrentCount--;
    12121212
    1213     tr_bandwidthFree( tor->bandwidth );
     1213    tr_bandwidthDestruct( &tor->bandwidth );
    12141214
    12151215    tr_metainfoFree( inf );
     
    17401740    assert( tr_isTorrent( tor ) );
    17411741
    1742     return tor->bandwidth->priority;
     1742    return tor->bandwidth.priority;
    17431743}
    17441744
     
    17491749    assert( tr_isPriority( priority ) );
    17501750
    1751     tor->bandwidth->priority = priority;
     1751    tor->bandwidth.priority = priority;
    17521752}
    17531753
  • trunk/libtransmission/torrent.h

    r8433 r8693  
    1818#define TR_TORRENT_H 1
    1919
     20#include "bandwidth.h" /* tr_bandwidth */
    2021#include "completion.h" /* tr_completion */
    2122#include "ratecontrol.h" /* tr_ratecontrol */
     
    173174    tr_completeness            completeness;
    174175
     176    struct tr_bandwidth        bandwidth;
     177
    175178    struct tr_tracker *        tracker;
    176179    struct tr_publisher_tag *  trackerSubscription;
     
    214217    int                        uniqueId;
    215218
    216     struct tr_bandwidth      * bandwidth;
    217 
    218219    struct tr_torrent_peers  * torrentPeers;
    219220
Note: See TracChangeset for help on using the changeset viewer.