Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.58 KB | None | 0 0
  1. Index: peer-mgr.c
  2. ===================================================================
  3. --- peer-mgr.c (revision 12005)
  4. +++ peer-mgr.c (working copy)
  5. @@ -3115,10 +3115,7 @@
  6. }
  7. else
  8. {
  9. - tr_bitfield * tmp = tr_bitfieldDup( tr_cpPieceBitfield( &tor->completion ) );
  10. - tr_bitsetDifference( tmp, &peer->have );
  11. - peerHasEverything = tr_bitfieldCountTrueBits( tmp ) == 0;
  12. - tr_bitfieldFree( tmp );
  13. + peerHasEverything = !tr_bitsetIsMissing( tr_cpPieceBitfield( &tor->completion ), &peer->have );
  14. }
  15.  
  16. if( peerHasEverything && ( !tr_torrentAllowsPex(tor) || (now-atom->time>=30 )))
  17. Index: bitset.c
  18. ===================================================================
  19. --- bitset.c (revision 12005)
  20. +++ bitset.c (working copy)
  21. @@ -60,14 +60,16 @@
  22. tr_bitfieldOr( a, &b->bitfield );
  23. }
  24.  
  25. -/* set 'a' to all the flags that were in 'a' but not 'b' */
  26. -void
  27. -tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b )
  28. +/* returns if 'base' contains bits that 'compare' does not */
  29. +tr_bool
  30. +tr_bitsetIsMissing( const tr_bitfield * base, const tr_bitset * compare )
  31. {
  32. - if( b->haveAll )
  33. - tr_bitfieldClear( a );
  34. - else if( !b->haveNone )
  35. - tr_bitfieldDifference( a, &b->bitfield );
  36. + if( compare->haveAll )
  37. + return FALSE;
  38. + else if( compare->haveNone )
  39. + return TRUE;
  40. + else
  41. + return tr_bitfieldIsMissing( base, &compare->bitfield );
  42. }
  43.  
  44. double
  45. Index: bitset.h
  46. ===================================================================
  47. --- bitset.h (revision 12005)
  48. +++ bitset.h (working copy)
  49. @@ -48,7 +48,7 @@
  50.  
  51. void tr_bitsetOr( tr_bitfield * a, const tr_bitset * b );
  52.  
  53. -/* set 'a' to all the flags that were in 'a' but not 'b' */
  54. -void tr_bitsetDifference( tr_bitfield * a, const tr_bitset * b );
  55. +/* returns if 'base' contains bits that 'compare' does not */
  56. +tr_bool tr_bitsetIsMissing( const tr_bitfield * base, const tr_bitset * compare );
  57.  
  58. #endif
  59. Index: bitfield.c
  60. ===================================================================
  61. --- bitfield.c (revision 12005)
  62. +++ bitfield.c (working copy)
  63. @@ -173,17 +173,20 @@
  64. return a;
  65. }
  66.  
  67. -/* set 'a' to all the flags that were in 'a' but not 'b' */
  68. -void
  69. -tr_bitfieldDifference( tr_bitfield * a, const tr_bitfield * b )
  70. +/* returns if 'base' contains bits that 'compare' does not */
  71. +tr_bool
  72. +tr_bitfieldIsMissing( const tr_bitfield * base, const tr_bitfield * compare )
  73. {
  74. - uint8_t * ait = a->bits;
  75. - const uint8_t * aend = ait + a->byteCount;
  76. - const uint8_t * bit = b->bits;
  77. - const uint8_t * bend = bit + b->byteCount;
  78. + uint8_t * baseIt = base->bits;
  79. + const uint8_t * baseEnd = baseIt + base->byteCount;
  80. + const uint8_t * compareIt = compare->bits;
  81. + const uint8_t * compareEnd = compareIt + compare->byteCount;
  82.  
  83. - while( ait!=aend && bit!=bend )
  84. - *ait++ &= ~( *bit++ );
  85. + for(; baseIt!=baseEnd && compareIt!=compareEnd; ++baseIt, ++compareIt )
  86. + if (*baseIt && !( *baseIt & *compareIt ) )
  87. + return TRUE;
  88. +
  89. + return FALSE;
  90. }
  91.  
  92. size_t
  93. Index: bitfield.h
  94. ===================================================================
  95. --- bitfield.h (revision 12005)
  96. +++ bitfield.h (working copy)
  97. @@ -55,7 +55,7 @@
  98.  
  99. int tr_bitfieldRemRange( tr_bitfield*, size_t begin, size_t end );
  100.  
  101. -void tr_bitfieldDifference( tr_bitfield *, const tr_bitfield * );
  102. +tr_bool tr_bitfieldIsMissing( const tr_bitfield*, const tr_bitfield* );
  103.  
  104. int tr_bitfieldIsEmpty( const tr_bitfield* );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement