mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
fix: Bitfield.getRaw() regression (#2023)
* fix: Bitfield.getRaw() regression
This commit is contained in:
@@ -21,17 +21,17 @@ static void tr_cpReset(tr_completion* cp)
|
||||
cp->sizeNow = 0;
|
||||
cp->sizeWhenDoneIsDirty = true;
|
||||
cp->haveValidIsDirty = true;
|
||||
cp->blockBitfield->setMode(Bitfield::OperationMode::None);
|
||||
cp->blockBitfield->setHasNone();
|
||||
}
|
||||
|
||||
void tr_cpConstruct(tr_completion* cp, tr_torrent* tor)
|
||||
{
|
||||
cp->tor = tor;
|
||||
cp->blockBitfield = new Bitfield(tor->blockCount);
|
||||
cp->blockBitfield = new tr_bitfield(tor->blockCount);
|
||||
tr_cpReset(cp);
|
||||
}
|
||||
|
||||
void tr_cpBlockInit(tr_completion* cp, Bitfield const& b)
|
||||
void tr_cpBlockInit(tr_completion* cp, tr_bitfield const& b)
|
||||
{
|
||||
tr_cpReset(cp);
|
||||
|
||||
@@ -39,11 +39,11 @@ void tr_cpBlockInit(tr_completion* cp, Bitfield const& b)
|
||||
*(cp->blockBitfield) = b;
|
||||
|
||||
// set sizeNow
|
||||
cp->sizeNow = cp->blockBitfield->countBits();
|
||||
cp->sizeNow = cp->blockBitfield->count();
|
||||
TR_ASSERT(cp->sizeNow <= cp->tor->blockCount);
|
||||
cp->sizeNow *= cp->tor->blockSize;
|
||||
|
||||
if (b.readBit(cp->tor->blockCount - 1))
|
||||
if (b.test(cp->tor->blockCount - 1))
|
||||
{
|
||||
cp->sizeNow -= (cp->tor->blockSize - cp->tor->lastBlockSize);
|
||||
}
|
||||
@@ -93,7 +93,7 @@ void tr_cpPieceRem(tr_completion* cp, tr_piece_index_t piece)
|
||||
|
||||
cp->haveValidIsDirty = true;
|
||||
cp->sizeWhenDoneIsDirty = true;
|
||||
cp->blockBitfield->clearBitRange(f, l + 1);
|
||||
cp->blockBitfield->setRange(f, l + 1, false);
|
||||
}
|
||||
|
||||
void tr_cpPieceAdd(tr_completion* cp, tr_piece_index_t piece)
|
||||
@@ -116,7 +116,7 @@ void tr_cpBlockAdd(tr_completion* cp, tr_block_index_t block)
|
||||
{
|
||||
tr_piece_index_t const piece = tr_torBlockPiece(cp->tor, block);
|
||||
|
||||
cp->blockBitfield->setBit(block);
|
||||
cp->blockBitfield->set(block);
|
||||
cp->sizeNow += tr_torBlockCountBytes(tor, block);
|
||||
|
||||
cp->haveValidIsDirty = true;
|
||||
@@ -182,10 +182,10 @@ uint64_t tr_cpSizeWhenDone(tr_completion const* ccp)
|
||||
auto l = tr_block_index_t{};
|
||||
tr_torGetPieceBlockRange(cp->tor, p, &f, &l);
|
||||
|
||||
n = cp->blockBitfield->countRange(f, l + 1);
|
||||
n = cp->blockBitfield->count(f, l + 1);
|
||||
n *= cp->tor->blockSize;
|
||||
|
||||
if (l == cp->tor->blockCount - 1 && cp->blockBitfield->readBit(l))
|
||||
if (l == cp->tor->blockCount - 1 && cp->blockBitfield->test(l))
|
||||
{
|
||||
n -= cp->tor->blockSize - cp->tor->lastBlockSize;
|
||||
}
|
||||
@@ -232,7 +232,7 @@ void tr_cpGetAmountDone(tr_completion const* cp, float* tab, int tabCount)
|
||||
auto f = tr_block_index_t{};
|
||||
auto l = tr_block_index_t{};
|
||||
tr_torGetPieceBlockRange(cp->tor, piece, &f, &l);
|
||||
tab[i] = cp->blockBitfield->countRange(f, l + 1) / (float)(l + 1 - f);
|
||||
tab[i] = cp->blockBitfield->count(f, l + 1) / (float)(l + 1 - f);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -247,7 +247,7 @@ size_t tr_cpMissingBlocksInPiece(tr_completion const* cp, tr_piece_index_t piece
|
||||
auto f = tr_block_index_t{};
|
||||
auto l = tr_block_index_t{};
|
||||
tr_torGetPieceBlockRange(cp->tor, piece, &f, &l);
|
||||
return (l + 1 - f) - cp->blockBitfield->countRange(f, l + 1);
|
||||
return (l + 1 - f) - cp->blockBitfield->count(f, l + 1);
|
||||
}
|
||||
|
||||
size_t tr_cpMissingBytesInPiece(tr_completion const* cp, tr_piece_index_t piece)
|
||||
@@ -268,11 +268,11 @@ size_t tr_cpMissingBytesInPiece(tr_completion const* cp, tr_piece_index_t piece)
|
||||
/* nb: we don't pass the usual l+1 here to Bitfield::countRange().
|
||||
It's faster to handle the last block separately because its size
|
||||
needs to be checked separately. */
|
||||
haveBytes = cp->blockBitfield->countRange(f, l);
|
||||
haveBytes = cp->blockBitfield->count(f, l);
|
||||
haveBytes *= cp->tor->blockSize;
|
||||
}
|
||||
|
||||
if (cp->blockBitfield->readBit(l)) /* handle the last block */
|
||||
if (cp->blockBitfield->test(l)) /* handle the last block */
|
||||
{
|
||||
haveBytes += tr_torBlockCountBytes(cp->tor, l);
|
||||
}
|
||||
@@ -291,7 +291,7 @@ bool tr_cpFileIsComplete(tr_completion const* cp, tr_file_index_t i)
|
||||
auto f = tr_block_index_t{};
|
||||
auto l = tr_block_index_t{};
|
||||
tr_torGetFileBlockRange(cp->tor, i, &f, &l);
|
||||
return cp->blockBitfield->countRange(f, l + 1) == (l + 1 - f);
|
||||
return cp->blockBitfield->count(f, l + 1) == (l + 1 - f);
|
||||
}
|
||||
|
||||
std::vector<uint8_t> tr_cpCreatePieceBitfield(tr_completion const* cp)
|
||||
@@ -300,11 +300,11 @@ std::vector<uint8_t> tr_cpCreatePieceBitfield(tr_completion const* cp)
|
||||
|
||||
auto const n = cp->tor->info.pieceCount;
|
||||
|
||||
Bitfield pieces(n);
|
||||
auto pieces = tr_bitfield{ n };
|
||||
|
||||
if (tr_cpHasAll(cp))
|
||||
{
|
||||
pieces.setMode(Bitfield::OperationMode::All);
|
||||
pieces.setHasAll();
|
||||
}
|
||||
else if (!tr_cpHasNone(cp))
|
||||
{
|
||||
@@ -315,11 +315,11 @@ std::vector<uint8_t> tr_cpCreatePieceBitfield(tr_completion const* cp)
|
||||
flags[i] = tr_cpPieceIsComplete(cp, i);
|
||||
}
|
||||
|
||||
pieces = Bitfield(flags, n);
|
||||
pieces.setFromBools(flags, n);
|
||||
tr_free(flags);
|
||||
}
|
||||
|
||||
return pieces.getRaw();
|
||||
return pieces.raw();
|
||||
}
|
||||
|
||||
double tr_cpPercentComplete(tr_completion const* cp)
|
||||
|
||||
Reference in New Issue
Block a user