Changeset 8218


Ignore:
Timestamp:
Apr 12, 2009, 3:01:29 PM (13 years ago)
Author:
charles
Message:

(1.5x libT) backport speedups r8217, r8215, r8214, r8212

Location:
branches/1.5x/libtransmission
Files:
7 edited

Legend:

Unmodified
Added
Removed
  • branches/1.5x/libtransmission/completion.c

    r7813 r8218  
    8383                /* we have part of the piece... */
    8484                const tr_block_index_t b = tr_torPieceFirstBlock( tor, i );
    85                 const tr_block_index_t e = b + tr_torPieceCountBlocks( tor,
    86                                                                        i );
    87                 tr_block_index_t       j;
     85                const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i );
     86                tr_block_index_t j;
    8887                for( j = b; j < e; ++j )
    89                     if( tr_cpBlockIsComplete( cp, j ) )
     88                    if( tr_cpBlockIsCompleteFast( cp, j ) )
    9089                        size += tr_torBlockCountBytes( tor, j );
    9190            }
     
    130129
    131130    for( block = start; block < end; ++block )
    132         if( tr_cpBlockIsComplete( cp, block ) )
     131        if( tr_cpBlockIsCompleteFast( cp, block ) )
    133132            cp->sizeNow -= tr_torBlockCountBytes( tor, block );
    134133
     
    344343
    345344    for( block=firstBlock; block<=lastBlock; ++block )
    346         if( !tr_cpBlockIsComplete( cp, block ) )
     345        if( !tr_cpBlockIsCompleteFast( cp, block ) )
    347346            return FALSE;
    348347
  • branches/1.5x/libtransmission/completion.h

    r7722 r8218  
    135135**/
    136136
    137 static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block ) {
     137static TR_INLINE tr_bool tr_cpBlockIsCompleteFast( const tr_completion * cp, tr_block_index_t block )
     138{
     139    return tr_bitfieldHasFast( &cp->blockBitfield, block );
     140}
     141
     142static TR_INLINE tr_bool tr_cpBlockIsComplete( const tr_completion * cp, tr_block_index_t block )
     143{
    138144    return tr_bitfieldHas( &cp->blockBitfield, block );
    139145}
  • branches/1.5x/libtransmission/net.c

    r8204 r8218  
    181181tr_compareAddresses( const tr_address * a, const tr_address * b)
    182182{
    183     int addrlen;
     183    static const int sizes[2] = { sizeof(struct in_addr), sizeof(struct in6_addr) };
    184184
    185185    assert( tr_isAddress( a ) );
     
    190190        return a->type == TR_AF_INET ? 1 : -1;
    191191
    192     if( a->type == TR_AF_INET )
    193         addrlen = sizeof( struct in_addr );
    194     else
    195         addrlen = sizeof( struct in6_addr );
    196     return memcmp( &a->addr, &b->addr, addrlen );
     192    return memcmp( &a->addr, &b->addr, sizes[a->type] );
    197193}
    198194
  • branches/1.5x/libtransmission/peer-io.c

    r7813 r8218  
    741741
    742742        case PEER_ENCRYPTION_RC4:
    743             evbuffer_remove( inbuf, bytes, byteCount );
    744             tr_cryptoDecrypt( io->crypto, byteCount, bytes, bytes );
     743            tr_cryptoDecrypt( io->crypto, byteCount, EVBUFFER_DATA(inbuf), bytes );
     744            evbuffer_drain(inbuf, byteCount );
    745745            break;
    746746
  • branches/1.5x/libtransmission/peer-mgr.c

    r8204 r8218  
    694694        i->blockIndex = 0;
    695695        for( block=b; block!=e; ++block )
    696             if( !tr_cpBlockIsComplete( &tor->completion, block ) )
     696            if( !tr_cpBlockIsCompleteFast( &tor->completion, block ) )
    697697                i->blocks[i->blockCount++] = block;
    698698    }
  • branches/1.5x/libtransmission/torrent.c

    r8204 r8218  
    321321tr_torrentInitFilePieces( tr_torrent * tor )
    322322{
    323     tr_file_index_t  ff;
    324     tr_piece_index_t pp;
    325     uint64_t         offset = 0;
    326     tr_info *        inf = &tor->info;
    327 
    328     assert( inf );
    329 
    330     for( ff = 0; ff < inf->fileCount; ++ff )
    331     {
    332         inf->files[ff].offset = offset;
    333         offset += inf->files[ff].length;
    334         initFilePieces( inf, ff );
    335     }
    336 
    337     for( pp = 0; pp < inf->pieceCount; ++pp )
    338         inf->pieces[pp].priority = calculatePiecePriority( tor, pp, -1 );
     323    tr_file_index_t  f;
     324    tr_piece_index_t p;
     325    uint64_t offset = 0;
     326    tr_info * inf = &tor->info;
     327    int * firstFiles;
     328
     329    /* assign the file offsets */
     330    for( f=0; f<inf->fileCount; ++f ) {
     331        inf->files[f].offset = offset;
     332        offset += inf->files[f].length;
     333        initFilePieces( inf, f );
     334    }
     335
     336    /* build the array of first-file hints to give calculatePiecePriority */
     337    firstFiles = tr_new( int, inf->pieceCount );
     338    for( p=f=0; p<inf->pieceCount; ++p ) {
     339        while( inf->files[f].lastPiece < p )
     340            ++f;
     341        firstFiles[p] = f;
     342    }
     343
     344#if 0
     345    /* test to confirm the first-file hints are correct */
     346    for( p=0; p<inf->pieceCount; ++p ) {
     347        f = firstFiles[p];
     348        assert( inf->files[f].firstPiece <= p );
     349        assert( inf->files[f].lastPiece >= p );
     350        if( f > 0 )
     351            assert( inf->files[f-1].lastPiece < p );
     352        for( f=0; f<inf->fileCount; ++f )
     353            if( pieceHasFile( p, &inf->files[f] ) )
     354                break;
     355        assert( (int)f == firstFiles[p] );
     356    }
     357#endif
     358
     359    for( p=0; p<inf->pieceCount; ++p )
     360        inf->pieces[p].priority = calculatePiecePriority( tor, p, firstFiles[p] );
     361
     362    tr_free( firstFiles );
    339363}
    340364
     
    816840        s->desiredAvailable = 0;
    817841        for( i = 0; i < tor->info.pieceCount; ++i )
    818             if( !tor->info.pieces[i].dnd && tr_bitfieldHas( peerPieces, i ) )
     842            if( !tor->info.pieces[i].dnd && tr_bitfieldHasFast( peerPieces, i ) )
    819843                s->desiredAvailable += tr_cpMissingBlocksInPiece( &tor->completion, i );
    820844        s->desiredAvailable *= tor->blockSize;
     
    873897    if( firstBlock == lastBlock )
    874898    {
    875         if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
     899        if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
    876900            haveBytes += lastBlockOffset + 1 - firstBlockOffset;
    877901    }
     
    880904        tr_block_index_t i;
    881905
    882         if( tr_cpBlockIsComplete( &tor->completion, firstBlock ) )
     906        if( tr_cpBlockIsCompleteFast( &tor->completion, firstBlock ) )
    883907            haveBytes += tor->blockSize - firstBlockOffset;
    884908
    885909        for( i = firstBlock + 1; i < lastBlock; ++i )
    886             if( tr_cpBlockIsComplete( &tor->completion, i ) )
     910            if( tr_cpBlockIsCompleteFast( &tor->completion, i ) )
    887911                haveBytes += tor->blockSize;
    888912
    889         if( tr_cpBlockIsComplete( &tor->completion, lastBlock ) )
     913        if( tr_cpBlockIsCompleteFast( &tor->completion, lastBlock ) )
    890914            haveBytes += lastBlockOffset + 1;
    891915    }
  • branches/1.5x/libtransmission/torrent.h

    r7813 r8218  
    277277static TR_INLINE tr_bool tr_torrentIsPieceChecked( const tr_torrent  * tor, tr_piece_index_t i )
    278278{
    279     return tr_bitfieldHas( &tor->checkedPieces, i );
     279    return tr_bitfieldHasFast( &tor->checkedPieces, i );
    280280}
    281281
Note: See TracChangeset for help on using the changeset viewer.