From cf96e6c64266bf11ba9cf3dc7d2eaf7628c6d7a9 Mon Sep 17 00:00:00 2001 From: Chocobo1 Date: Wed, 9 Feb 2022 17:24:54 +0800 Subject: [PATCH] Use QVarLengthArray whenever applicable --- src/base/bittorrent/ltqbitarray.cpp | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/base/bittorrent/ltqbitarray.cpp b/src/base/bittorrent/ltqbitarray.cpp index 83b62a8d0..940c3f8ce 100644 --- a/src/base/bittorrent/ltqbitarray.cpp +++ b/src/base/bittorrent/ltqbitarray.cpp @@ -28,11 +28,10 @@ #include "ltqbitarray.h" -#include - #include #include +#include namespace { @@ -52,21 +51,10 @@ namespace BitTorrent::LT const char *bitsData = bits.data(); const int dataLength = (bits.size() + 7) / 8; - if (dataLength <= STACK_ALLOC_SIZE) - { - // 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(dataLength); + QVarLengthArray tmp(dataLength); for (int i = 0; i < dataLength; ++i) tmp[i] = reverseByte(bitsData[i]); - return QBitArray::fromBits(tmp.get(), bits.size()); + return QBitArray::fromBits(tmp.data(), tmp.size()); } }