Changeset 7614


Ignore:
Timestamp:
Jan 4, 2009, 4:59:15 PM (12 years ago)
Author:
charles
Message:

(trunk libT) minor tr_ptrArray API cleanup

Location:
trunk/libtransmission
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bandwidth.c

    r7594 r7614  
    183183    if( 1 ) {
    184184        int i;
    185         struct tr_bandwidth ** children = (struct tr_bandwidth**) TR_PTR_ARRAY_DATA( &b->children );
    186         const int n = TR_PTR_ARRAY_LENGTH( &b->children );
     185        struct tr_bandwidth ** children = (struct tr_bandwidth**) tr_ptrArrayBase( &b->children );
     186        const int n = tr_ptrArraySize( &b->children );
    187187        for( i=0; i<n; ++i )
    188188            allocateBandwidth( children[i], dir, period_msec, peer_pool );
     
    203203     * 2. accumulate an array of all the peerIos from b and its subtree. */
    204204    allocateBandwidth( b, dir, period_msec, &tmp );
    205     peers = (struct tr_peerIo**) TR_PTR_ARRAY_DATA( &tmp );
    206     peerCount = TR_PTR_ARRAY_LENGTH( &tmp );
     205    peers = (struct tr_peerIo**) tr_ptrArrayBase( &tmp );
     206    peerCount = tr_ptrArraySize( &tmp );
    207207
    208208    /* Stop all peers from listening for the socket to be ready for IO.
  • trunk/libtransmission/peer-mgr.c

    r7597 r7614  
    620620    assert( torrentIsLocked( t ) );
    621621
    622     peers = (const tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
    623     peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
     622    peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
     623    peerCount = tr_ptrArraySize( &t->peers );
    624624
    625625    /* make a list of the pieces that we want but don't have */
     
    791791    peers = getPeersUploadingToClient( t, &peerCount );
    792792    webseedCount = tr_ptrArraySize( &t->webseeds );
    793     webseeds = tr_memdup( TR_PTR_ARRAY_DATA( &t->webseeds ),
     793    webseeds = tr_memdup( tr_ptrArrayBase( &t->webseeds ),
    794794                          webseedCount * sizeof( tr_webseed* ) );
    795795
     
    874874    tordbg( t, "got a block; cancelling any duplicate requests from peers %"PRIu32":%"PRIu32"->%"PRIu32, index, offset, length );
    875875
    876     peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
    877     peers = (tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
     876    peerCount = tr_ptrArraySize( &t->peers );
     877    peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
    878878    for( i=0; i<peerCount; ++i )
    879879        if( peers[i]->msgs )
     
    11041104                {
    11051105                    int i;
    1106                     int peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
    1107                     tr_peer ** peers = (tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
     1106                    int peerCount = tr_ptrArraySize( &t->peers );
     1107                    tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
    11081108                    for( i=0; i<peerCount; ++i )
    11091109                        tr_peerMsgsHave( peers[i]->msgs, p );
     
    15021502    {
    15031503        int i;
    1504         const tr_peer ** peers = (const tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
    1505         const int peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
     1504        const tr_peer ** peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
     1505        const int peerCount = tr_ptrArraySize( &t->peers );
    15061506        /* for now, this will waste memory on torrents that have both
    15071507         * ipv6 and ipv4 peers */
     
    16621662    interval = tor->info.pieceCount / (float)tabCount;
    16631663    isSeed = tor && ( tr_cpGetStatus ( &tor->completion ) == TR_SEED );
    1664     peers = (const tr_peer **) TR_PTR_ARRAY_DATA( &t->peers );
    1665     peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
     1664    peers = (const tr_peer **) tr_ptrArrayBase( &t->peers );
     1665    peerCount = tr_ptrArraySize( &t->peers );
    16661666
    16671667    memset( tab, 0, tabCount );
     
    16981698    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
    16991699    pieces = tr_bitfieldNew( t->tor->info.pieceCount );
    1700     peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
    1701     peers = (const tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
     1700    peerCount = tr_ptrArraySize( &t->peers );
     1701    peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
    17021702    for( i=0; i<peerCount; ++i )
    17031703        tr_bitfieldOr( pieces, peers[i]->have );
     
    17411741
    17421742    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
    1743     peers = (const tr_peer **) TR_PTR_ARRAY_DATA( &t->peers );
    1744     size = TR_PTR_ARRAY_LENGTH( &t->peers );
     1743    peers = (const tr_peer **) tr_ptrArrayBase( &t->peers );
     1744    size = tr_ptrArraySize( &t->peers );
    17451745
    17461746    *setmePeersKnown           = tr_ptrArraySize( &t->pool );
     
    17761776    }
    17771777
    1778     webseeds = (const tr_webseed**) TR_PTR_ARRAY_DATA( &t->webseeds );
    1779     size = TR_PTR_ARRAY_LENGTH( &t->webseeds );
     1778    webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds );
     1779    size = tr_ptrArraySize( &t->webseeds );
    17801780    for( i=0; i<size; ++i )
    17811781        if( tr_webseedIsActive( webseeds[i] ) )
     
    17991799
    18001800    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
    1801     webseeds = (const tr_webseed**) TR_PTR_ARRAY_DATA( &t->webseeds );
    1802     webseedCount = TR_PTR_ARRAY_LENGTH( &t->webseeds );
     1801    webseeds = (const tr_webseed**) tr_ptrArrayBase( &t->webseeds );
     1802    webseedCount = tr_ptrArraySize( &t->webseeds );
    18031803    assert( webseedCount == t->tor->info.webseedCount );
    18041804    ret = tr_new0( float, webseedCount );
     
    18331833
    18341834    t = getExistingTorrent( (tr_peerMgr*)manager, torrentHash );
    1835     size = TR_PTR_ARRAY_LENGTH( &t->peers );
    1836     peers = (const tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
     1835    size = tr_ptrArraySize( &t->peers );
     1836    peers = (const tr_peer**) tr_ptrArrayBase( &t->peers );
    18371837    ret = tr_new0( tr_peer_stat, size );
    18381838
     
    19341934{
    19351935    int i, size, unchokedInterested;
    1936     const int peerCount = TR_PTR_ARRAY_LENGTH( &t->peers );
    1937     tr_peer ** peers = (tr_peer**) TR_PTR_ARRAY_DATA( &t->peers );
     1936    const int peerCount = tr_ptrArraySize( &t->peers );
     1937    tr_peer ** peers = (tr_peer**) tr_ptrArrayBase( &t->peers );
    19381938    struct ChokeData * choke = tr_new0( struct ChokeData, peerCount );
    19391939    const int chokeAll = !tr_torrentIsPieceTransferAllowed( t->tor, TR_CLIENT_TO_PEER );
  • trunk/libtransmission/ptrarray.h

    r7582 r7614  
    4343tr_ptrArray;
    4444
    45 #define TR_PTR_ARRAY_DATA( A ) ((A)->items)
    46 #define TR_PTR_ARRAY_LENGTH( A ) ((A)->n_items)
    47 
    4845typedef void ( *PtrArrayForeachFunc )( void * );
    4946
     
    8784                                int            end );
    8885
     86static inline void** tr_ptrArrayBase( const tr_ptrArray * a )
     87{
     88    return a->items;
     89}
     90
    8991static inline int tr_ptrArraySize( const tr_ptrArray *  a )
    9092{
Note: See TracChangeset for help on using the changeset viewer.