Changeset 8214


Ignore:
Timestamp:
Apr 11, 2009, 6:58:14 AM (13 years ago)
Author:
charles
Message:

(trunk libT) startup uses less cpu now on big torrents. another cachegrind discovery

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/torrent.c

    r8212 r8214  
    353353
    354354    /* find the first file that has data in this piece */
    355     if( fileHint >= 0 )
    356     {
     355    if( fileHint >= 0 ) {
    357356        i = fileHint;
    358357        while( i > 0 && pieceHasFile( piece, &tor->info.files[i - 1] ) )
    359358            --i;
    360     }
    361     else
    362     {
     359    } else {
    363360        for( i = 0; i < tor->info.fileCount; ++i )
    364361            if( pieceHasFile( piece, &tor->info.files[i] ) )
     
    391388tr_torrentInitFilePieces( tr_torrent * tor )
    392389{
    393     tr_file_index_t  ff;
    394     tr_piece_index_t pp;
    395     uint64_t         offset = 0;
    396     tr_info *        inf = &tor->info;
    397 
    398     assert( inf );
    399 
    400     for( ff = 0; ff < inf->fileCount; ++ff )
    401     {
    402         inf->files[ff].offset = offset;
    403         offset += inf->files[ff].length;
    404         initFilePieces( inf, ff );
    405     }
    406 
    407     for( pp = 0; pp < inf->pieceCount; ++pp )
    408         inf->pieces[pp].priority = calculatePiecePriority( tor, pp, -1 );
     390    tr_file_index_t  f;
     391    tr_piece_index_t p;
     392    uint64_t offset = 0;
     393    tr_info * inf = &tor->info;
     394    int * firstFiles;
     395
     396    /* assign the file offsets */
     397    for( f=0; f<inf->fileCount; ++f ) {
     398        inf->files[f].offset = offset;
     399        offset += inf->files[f].length;
     400        initFilePieces( inf, f );
     401    }
     402
     403    /* build the array of first-file hints to give calculatePiecePriority */
     404    firstFiles = tr_new( int, inf->pieceCount );
     405    for( p=f=0; p<inf->pieceCount; ++p ) {
     406        if( inf->files[f].lastPiece < p )
     407            ++f;
     408        firstFiles[p] = f;
     409    }
     410
     411
     412#if 0
     413    /* test to confirm the first-file hints are correct */
     414    for( p=0; p<inf->pieceCount; ++p ) {
     415        f = firstFiles[p];
     416        assert( inf->files[f].firstPiece <= p );
     417        assert( inf->files[f].lastPiece >= p );
     418        if( f > 0 )
     419            assert( inf->files[f-1].lastPiece < p );
     420    }
     421#endif
     422
     423    for( p=0; p<inf->pieceCount; ++p )
     424        inf->pieces[p].priority = calculatePiecePriority( tor, p, firstFiles[p] );
     425
     426    tr_free( firstFiles );
    409427}
    410428
     
    15051523    file->priority = priority;
    15061524    for( i = file->firstPiece; i <= file->lastPiece; ++i )
    1507         tor->info.pieces[i].priority = calculatePiecePriority( tor, i,
    1508                                                                fileIndex );
     1525        tor->info.pieces[i].priority = calculatePiecePriority( tor, i, fileIndex );
    15091526}
    15101527
Note: See TracChangeset for help on using the changeset viewer.