Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: peer-mgr.c
- ===================================================================
- --- peer-mgr.c (revision 12005)
- +++ peer-mgr.c (working copy)
- @@ -3115,10 +3115,7 @@
- }
- else
- {
- - tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( &tor->completion ) );
- - tr_bitsetDifference( tmp, &peer->have );
- - peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0;
- - tr_bitfieldFree( tmp );
- + peerHasEverything = !tr_bitsetIsMissing( tr_cpPieceBitfield( &tor->completion ), &peer->have );
- }
- if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 )))
- Index: bitset.c
- ===================================================================
- --- bitset.c (revision 12005)
- +++ bitset.c (working copy)
- @@ -60,14 +60,16 @@
- tr_bitfieldOr( a, &b->bitfield );
- }
- -/* set 'a' to all the flags that were in 'a' but not 'b' */
- -void
- -tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b )
- +/* returns if 'base' contains bits that 'compare' does not */
- +tr_bool
- +tr_bitsetIsMissing( const tr_bitfield * base, const tr_bitset * compare )
- {
- - if( b->haveAll )
- - tr_bitfieldClear( a );
- - else if( !b->haveNone )
- - tr_bitfieldDifference( a, &b->bitfield );
- + if( compare->haveAll )
- + return FALSE;
- + else if( compare->haveNone )
- + return TRUE;
- + else
- + return tr_bitfieldIsMissing( base, &compare->bitfield );
- }
- double
- Index: bitset.h
- ===================================================================
- --- bitset.h (revision 12005)
- +++ bitset.h (working copy)
- @@ -48,7 +48,7 @@
- void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b );
- -/* set 'a' to all the flags that were in 'a' but not 'b' */
- -void tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b );
- +/* returns if 'base' contains bits that 'compare' does not */
- +tr_bool tr_bitsetIsMissing( const tr_bitfield * base, const tr_bitset * compare );
- #endif
- Index: bitfield.c
- ===================================================================
- --- bitfield.c (revision 12005)
- +++ bitfield.c (working copy)
- @@ -173,17 +173,20 @@
- return a;
- }
- -/* set 'a' to all the flags that were in 'a' but not 'b' */
- -void
- -tr_bitfieldDifference( tr_bitfield * a, const tr_bitfield * b )
- +/* returns if 'base' contains bits that 'compare' does not */
- +tr_bool
- +tr_bitfieldIsMissing( const tr_bitfield * base, const tr_bitfield * compare )
- {
- - uint8_t * ait = a->bits;
- - const uint8_t * aend = ait + a->byteCount;
- - const uint8_t * bit = b->bits;
- - const uint8_t * bend = bit + b->byteCount;
- + uint8_t * baseIt = base->bits;
- + const uint8_t * baseEnd = baseIt + base->byteCount;
- + const uint8_t * compareIt = compare->bits;
- + const uint8_t * compareEnd = compareIt + compare->byteCount;
- - while( ait!=aend && bit!=bend )
- - *ait++ &= ~( *bit++ );
- + for(; baseIt!=baseEnd && compareIt!=compareEnd; ++baseIt, ++compareIt )
- + if (*baseIt && !( *baseIt & *compareIt ) )
- + return TRUE;
- +
- + return FALSE;
- }
- size_t
- Index: bitfield.h
- ===================================================================
- --- bitfield.h (revision 12005)
- +++ bitfield.h (working copy)
- @@ -55,7 +55,7 @@
- int tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
- -void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
- +tr_bool tr_bitfieldIsMissing( const tr_bitfield*, const tr_bitfield* );
- int tr_bitfieldIsEmpty( const tr_bitfield* );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement