Ignore:
Timestamp:
Feb 23, 2011, 3:54:04 AM (11 years ago)
Author:
jordan
Message:

(trunk libT) #4048 "use bitsets instead of bitfield in tr_completion" -- done.

Excuse the sprawl. Much of this didn't fit into self-contained commits.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/cache.c

    r11782 r12012  
    390390
    391391static int
    392 findPiece( tr_cache * cache, tr_torrent * torrent, tr_piece_index_t piece )
     392findBlockPos( tr_cache * cache, tr_torrent * torrent, tr_piece_index_t block )
    393393{
    394394    struct cache_block key;
    395395    key.tor = torrent;
    396     key.block = tr_torPieceFirstBlock( torrent, piece );
     396    key.block = block;
    397397    return tr_ptrArrayLowerBound( &cache->blocks, &key, cache_block_compare, NULL );
    398398}
     
    420420tr_cacheFlushFile( tr_cache * cache, tr_torrent * torrent, tr_file_index_t i )
    421421{
    422     int err = 0;
    423     const tr_file * file = &torrent->info.files[i];
    424     const tr_block_index_t begin = tr_torPieceFirstBlock( torrent, file->firstPiece );
    425     const tr_block_index_t end  = tr_torPieceFirstBlock( torrent, file->lastPiece ) + tr_torPieceCountBlocks( torrent, file->lastPiece );
    426     const int pos = findPiece( cache, torrent, file->firstPiece );
    427     dbgmsg( "flushing file %d from cache to disk: blocks [%zu...%zu)", (int)i, (size_t)begin, (size_t)end );
     422    int pos;
     423    int err = 0;
     424    tr_block_index_t first;
     425    tr_block_index_t last;
     426    tr_torGetFileBlockRange( torrent, i, &first, &last );
     427    pos = findBlockPos( cache, torrent, first );
     428    dbgmsg( "flushing file %d from cache to disk: blocks [%zu...%zu]", (int)i, (size_t)first, (size_t)last );
    428429
    429430    /* flush out all the blocks in that file */
     
    432433        const struct cache_block * b = tr_ptrArrayNth( &cache->blocks, pos );
    433434        if( b->tor != torrent ) break;
    434         if( ( b->block < begin ) || ( b->block >= end ) ) break;
     435        if( ( b->block < first ) || ( b->block > last ) ) break;
    435436        err = flushContiguous( cache, pos, getBlockRun( cache, pos, NULL ) );
    436437    }
     
    443444{
    444445    int err = 0;
    445     const int pos = findPiece( cache, torrent, 0 );
     446    const int pos = findBlockPos( cache, torrent, 0 );
    446447
    447448    /* flush out all the blocks in that torrent */
Note: See TracChangeset for help on using the changeset viewer.