~bratsche/transmission/notify-actions

« back to all changes in this revision

Viewing changes to libtransmission/completion.c

  • Committer: Bazaar Package Importer
  • Date: 2008-10-31 13:11:43 UTC
  • Revision ID: jamesw@ubuntu.com-20081031131143-1xburb867kue4y07
Tags: upstream-ubuntu-1.32
ImportĀ upstreamĀ versionĀ 1.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/******************************************************************************
2
 
 * $Id: completion.c 5708 2008-04-27 06:44:39Z charles $
 
2
 * $Id: completion.c 6425 2008-08-01 16:43:22Z charles $
3
3
 *
4
4
 * Copyright (c) 2005-2008 Transmission authors and contributors
5
5
 *
105
105
        for( i=0; i<info->pieceCount; ++i )
106
106
        {
107
107
            if( !info->pieces[i].dnd ) {
108
 
                // we want the piece...
 
108
                /* we want the piece... */
109
109
                size += tr_torPieceCountBytes( tor, i );
110
110
            } else if( tr_cpPieceIsComplete( cp, i ) ) {
111
 
                // we have the piece...
 
111
                /* we have the piece... */
112
112
                size += tr_torPieceCountBytes( tor, i );
113
113
            } else if( cp->completeBlocks[i] ) {
114
 
                // we have part of the piece...
 
114
                /* we have part of the piece... */
115
115
                const tr_block_index_t b = tr_torPieceFirstBlock( tor, i );
116
116
                const tr_block_index_t e = b + tr_torPieceCountBlocks( tor, i );
117
117
                tr_block_index_t j;
163
163
    const tr_block_index_t end = start + tr_torPieceCountBlocks( tor, piece );
164
164
    tr_block_index_t block;
165
165
 
166
 
    assert( cp != NULL );
 
166
    assert( cp );
167
167
    assert( piece < tor->info.pieceCount );
168
168
    assert( start < tor->blockCount );
169
169
    assert( start <= end );
214
214
    assert( cp );
215
215
    assert( cp->blockBitfield );
216
216
    assert( cp->blockBitfield->bits );
217
 
    assert( cp->blockBitfield->len );
 
217
    assert( cp->blockBitfield->bitCount );
218
218
 
219
219
    return cp->blockBitfield;
220
220
}
228
228
    assert( bitfield );
229
229
    assert( cp->blockBitfield );
230
230
 
231
 
    if( !cp || !bitfield || ( bitfield->len != cp->blockBitfield->len ) )
 
231
    if( !tr_bitfieldTestFast( bitfield, cp->tor->blockCount-1 ) )
232
232
        return TR_ERROR_ASSERT;
233
233
 
234
234
    tr_cpReset( cp );
235
 
    for( i=0; i < cp->tor->blockCount; ++i )
236
 
        if( tr_bitfieldHas( bitfield, i ) )
 
235
    for( i=0; i<cp->tor->blockCount; ++i )
 
236
        if( tr_bitfieldHasFast( bitfield, i ) )
237
237
            tr_cpBlockAdd( cp, i );
238
238
 
239
239
    return 0;
304
304
void
305
305
tr_cpGetAmountDone( const tr_completion * cp, float * tab, int tabCount )
306
306
{
307
 
    const int tabSpan = cp->tor->blockCount / tabCount;
308
 
    tr_block_index_t block_i = 0;
309
 
    int tab_i;
310
 
    for( tab_i=0; tab_i<tabCount; ++tab_i ) {
311
 
        int loop, have;
312
 
        for( loop=have=0; loop<tabSpan; ++loop )
313
 
            if( tr_cpBlockIsComplete( cp, block_i++ ) )
314
 
                ++have;
315
 
        tab[tab_i] = (float)have / tabSpan;
 
307
    int i;
 
308
    const tr_torrent * tor = cp->tor;
 
309
    const float interval = tor->info.pieceCount / (float)tabCount;
 
310
    const int isComplete = tr_cpGetStatus ( tor->completion ) == TR_CP_COMPLETE;
 
311
 
 
312
    for( i=0; i<tabCount; ++i )
 
313
    {
 
314
        const tr_piece_index_t piece = i * interval;
 
315
 
 
316
        if( tor == NULL )
 
317
            tab[i] = 0.0f;
 
318
        else if( isComplete || tr_cpPieceIsComplete( cp, piece ) )
 
319
            tab[i] = 1.0f;
 
320
        else 
 
321
            tab[i] = (float)cp->completeBlocks[piece] / tr_torPieceCountBlocks( tor, piece );
316
322
    }
317
323
}