From 0fbdc6471c894903ca7b0a9c9513579581688126 Mon Sep 17 00:00:00 2001 From: "Vladimir Golovnev (Glassez)" Date: Thu, 29 Oct 2015 14:45:51 +0300 Subject: [PATCH] Fix DownloadedPiecesBar::bitfieldToFloatVector(). --- src/gui/properties/downloadedpiecesbar.cpp | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/src/gui/properties/downloadedpiecesbar.cpp b/src/gui/properties/downloadedpiecesbar.cpp index fad66e870..3cf4885ba 100644 --- a/src/gui/properties/downloadedpiecesbar.cpp +++ b/src/gui/properties/downloadedpiecesbar.cpp @@ -59,24 +59,17 @@ std::vector DownloadedPiecesBar::bitfieldToFloatVector(const libtorrent:: // image.x(1) = pieces.x(1.7 >= x < 3.4) for (int x = 0; x < reqSize; ++x) { - - // don't use previously calculated value "ratio" here!!! - // float cannot save irrational number like 7/9, if this number will be rounded up by std::ceil - // give you x2 == pieces.size(), and index out of range: pieces[x2] - // this code is safe, so keep that in mind when you try optimize more. - // tested with size = 3000000ul - // R - real - const float fromR = (x * vecin.size()) / (float)reqSize; - const float toR = ((x + 1) * vecin.size()) / (float)reqSize; + const float fromR = x * ratio; + const float toR = (x + 1) * ratio; // C - integer int fromC = fromR;// std::floor not needed int toC = std::ceil(toR); + if (toC > vecin.size()) + --toC; // position in pieces table - // libtorrent::bitfield::m_size is unsigned int(31 bits), so qlonglong is not needed - // tested with size = 3000000ul int x2 = fromC; // little speed up for really big pieces table, 10K+ size @@ -88,7 +81,7 @@ std::vector DownloadedPiecesBar::bitfieldToFloatVector(const libtorrent:: // case when calculated range is (15.2 >= x < 15.7) if (x2 == toCMinusOne) { if (vecin[x2]) { - value += toR - fromR; + value += ratio; } ++x2; }