mirror of
https://github.com/d47081/qBittorrent.git
synced 2025-02-09 05:14:23 +00:00
Use QVarLengthArray whenever applicable
This commit is contained in:
parent
dd1bd8ad10
commit
cf96e6c642
@ -28,11 +28,10 @@
|
|||||||
|
|
||||||
#include "ltqbitarray.h"
|
#include "ltqbitarray.h"
|
||||||
|
|
||||||
#include <memory>
|
|
||||||
|
|
||||||
#include <libtorrent/bitfield.hpp>
|
#include <libtorrent/bitfield.hpp>
|
||||||
|
|
||||||
#include <QBitArray>
|
#include <QBitArray>
|
||||||
|
#include <QVarLengthArray>
|
||||||
|
|
||||||
namespace
|
namespace
|
||||||
{
|
{
|
||||||
@ -52,21 +51,10 @@ namespace BitTorrent::LT
|
|||||||
const char *bitsData = bits.data();
|
const char *bitsData = bits.data();
|
||||||
const int dataLength = (bits.size() + 7) / 8;
|
const int dataLength = (bits.size() + 7) / 8;
|
||||||
|
|
||||||
if (dataLength <= STACK_ALLOC_SIZE)
|
QVarLengthArray<char, STACK_ALLOC_SIZE> tmp(dataLength);
|
||||||
{
|
|
||||||
// fast path for small bitfields
|
|
||||||
char tmp[STACK_ALLOC_SIZE]; // uninitialized for faster allocation
|
|
||||||
for (int i = 0; i < dataLength; ++i)
|
|
||||||
tmp[i] = reverseByte(bitsData[i]);
|
|
||||||
|
|
||||||
return QBitArray::fromBits(tmp, bits.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
// slow path for big bitfields
|
|
||||||
auto tmp = std::make_unique<char []>(dataLength);
|
|
||||||
for (int i = 0; i < dataLength; ++i)
|
for (int i = 0; i < dataLength; ++i)
|
||||||
tmp[i] = reverseByte(bitsData[i]);
|
tmp[i] = reverseByte(bitsData[i]);
|
||||||
|
|
||||||
return QBitArray::fromBits(tmp.get(), bits.size());
|
return QBitArray::fromBits(tmp.data(), tmp.size());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user