Ignore:
Timestamp:
Jan 2, 2009, 5:01:55 PM (14 years ago)
Author:
charles
Message:

(trunk libT) avoid some unnecessary memory fragmentation... for composited objects that have a tr_completion, contain the it directly rather than a pointer to one allocated elsewhere on the heap.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r7576 r7578  
    8888}
    8989
    90 tr_bool
    91 tr_torrentExists( const tr_session * session, const uint8_t *   torrentHash )
    92 {
    93     return tr_torrentFindFromHash( (tr_session*)session, torrentHash ) != NULL;
    94 }
    95 
    9690tr_torrent*
    9791tr_torrentFindFromHash( tr_session * session, const uint8_t * torrentHash )
     
    119113
    120114    return NULL;
    121 }
    122 
    123 /***
    124 ****  LOCKS
    125 ***/
    126 
    127 void
    128 tr_torrentLock( const tr_torrent * tor )
    129 {
    130     tr_globalLock( tor->session );
    131 }
    132 
    133 void
    134 tr_torrentUnlock( const tr_torrent * tor )
    135 {
    136     tr_globalUnlock( tor->session );
    137115}
    138116
     
    520498    assert( t == (uint64_t)tor->blockCount );
    521499
    522     tor->completion = tr_cpInit( tor );
     500    tr_cpConstruct( &tor->completion, tor );
    523501
    524502    tr_torrentInitFilePieces( tor );
     
    557535    }
    558536
    559     tor->completeness = tr_cpGetStatus( tor->completion );
     537    tor->completeness = tr_cpGetStatus( &tor->completion );
    560538
    561539    tor->tracker = tr_trackerNew( tor );
     
    803781    usableSeeds += tor->info.webseedCount;
    804782
    805     s->percentComplete = tr_cpPercentComplete ( tor->completion );
    806 
    807     s->percentDone = tr_cpPercentDone( tor->completion );
    808     s->leftUntilDone = tr_cpLeftUntilDone( tor->completion );
    809     s->sizeWhenDone = tr_cpSizeWhenDone( tor->completion );
     783    s->percentComplete = tr_cpPercentComplete ( &tor->completion );
     784
     785    s->percentDone   = tr_cpPercentDone  ( &tor->completion );
     786    s->leftUntilDone = tr_cpLeftUntilDone( &tor->completion );
     787    s->sizeWhenDone  = tr_cpSizeWhenDone ( &tor->completion );
    810788
    811789    s->recheckProgress = s->activity == TR_STATUS_CHECK
     
    825803    s->downloadedEver  = tor->downloadedCur + tor->downloadedPrev;
    826804    s->uploadedEver    = tor->uploadedCur   + tor->uploadedPrev;
    827     s->haveValid       = tr_cpHaveValid( tor->completion );
    828     s->haveUnchecked   = tr_cpHaveTotal( tor->completion ) - s->haveValid;
     805    s->haveValid       = tr_cpHaveValid( &tor->completion );
     806    s->haveUnchecked   = tr_cpHaveTotal( &tor->completion ) - s->haveValid;
    829807
    830808
     
    847825        for( i = 0; i < tor->info.pieceCount; ++i )
    848826            if( !tor->info.pieces[i].dnd && tr_bitfieldHas( peerPieces, i ) )
    849                 s->desiredAvailable += tr_cpMissingBlocksInPiece(
    850                     tor->completion, i );
     827                s->desiredAvailable += tr_cpMissingBlocksInPiece( &tor->completion, i );
    851828        s->desiredAvailable *= tor->blockSize;
    852829        tr_bitfieldFree( peerPieces );
     
    904881    if( firstBlock == lastBlock )
    905882    {
    906         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     883        if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
    907884            haveBytes += lastBlockOffset + 1 - firstBlockOffset;
    908885    }
     
    911888        tr_block_index_t i;
    912889
    913         if( tr_cpBlockIsComplete( tor->completion, firstBlock ) )
     890        if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
    914891            haveBytes += tor->blockSize - firstBlockOffset;
    915892
    916893        for( i = firstBlock + 1; i < lastBlock; ++i )
    917             if( tr_cpBlockIsComplete( tor->completion, i ) )
     894            if( tr_cpBlockIsComplete( &tor->completion, i ) )
    918895                haveBytes += tor->blockSize;
    919896
    920         if( tr_cpBlockIsComplete( tor->completion, lastBlock ) )
     897        if( tr_cpBlockIsComplete( &tor->completion, lastBlock ) )
    921898            haveBytes += lastBlockOffset + 1;
    922899    }
     
    1001978{
    1002979    tr_torrentLock( tor );
    1003     tr_cpGetAmountDone( tor->completion, tab, size );
     980    tr_cpGetAmountDone( &tor->completion, tab, size );
    1004981    tr_torrentUnlock( tor );
    1005982}
     
    10311008
    10321009    if( has )
    1033         tr_cpPieceAdd( tor->completion, pieceIndex );
     1010        tr_cpPieceAdd( &tor->completion, pieceIndex );
    10341011    else
    1035         tr_cpPieceRem( tor->completion, pieceIndex );
     1012        tr_cpPieceRem( &tor->completion, pieceIndex );
    10361013
    10371014    tr_torrentUnlock( tor );
     
    10561033    tr_peerMgrRemoveTorrent( session->peerMgr, tor->info.hash );
    10571034
    1058     tr_cpClose( tor->completion );
     1035    tr_cpDestruct( &tor->completion );
    10591036
    10601037    tr_rcClose( tor->swarmSpeed );
     
    11031080    *tor->errorString = '\0';
    11041081    tr_torrentResetTransferStats( tor );
    1105     tor->completeness = tr_cpGetStatus( tor->completion );
     1082    tor->completeness = tr_cpGetStatus( &tor->completion );
    11061083    tr_torrentSaveResume( tor );
    11071084    tor->startDate = time( NULL );
     
    13071284    tr_torrentLock( tor );
    13081285
    1309     completeness = tr_cpGetStatus( tor->completion );
     1286    completeness = tr_cpGetStatus( &tor->completion );
    13101287
    13111288    if( completeness != tor->completeness )
     
    15001477    for( i = 0; i < fileCount; ++i )
    15011478        setFileDND( tor, files[i], doDownload );
    1502     tr_cpInvalidateDND ( tor->completion );
     1479    tr_cpInvalidateDND ( &tor->completion );
    15031480
    15041481    tr_torrentUnlock( tor );
Note: See TracChangeset for help on using the changeset viewer.