From 275c6f321506516e4f8f1bfb2dab778437893d7c Mon Sep 17 00:00:00 2001 From: Doug Hoyte Date: Sat, 2 Sep 2023 04:05:21 -0400 Subject: [PATCH] remove std::reverse optimisation (wrong layer), bugfixes --- cpp/Negentropy.h | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/cpp/Negentropy.h b/cpp/Negentropy.h index 301c6f5..1cc30e0 100644 --- a/cpp/Negentropy.h +++ b/cpp/Negentropy.h @@ -97,7 +97,6 @@ struct Negentropy { void seal() { if (sealed) throw negentropy::err("already sealed"); - std::reverse(items.begin(), items.end()); // typically pushed in approximately descending order so this may speed up the sort std::sort(items.begin(), items.end()); sealed = true; } @@ -191,7 +190,7 @@ struct Negentropy { payload += encodeVarInt(responseHaveIds.size()); for (const auto &id : responseHaveIds) payload += id; - auto nextSplitBound = it >= upper ? currBound : getMinimalBound(*it, *std::next(it)); + auto nextSplitBound = std::next(it) >= upper ? currBound : getMinimalBound(*it, *std::next(it)); outputs.emplace_back(BoundOutput({ didSplit ? splitBound : prevBound, @@ -257,7 +256,7 @@ struct Negentropy { outputs.emplace_back(BoundOutput({ i == 0 ? lowerBound : prevBound, - getMinimalBound(*std::prev(curr), *curr), + curr == items.end() ? upperBound : getMinimalBound(*std::prev(curr), *curr), std::move(payload) })); @@ -294,9 +293,8 @@ struct Negentropy { if (frameSizeLimit && output.size() + o.size() > frameSizeLimit - 5) break; // 5 leaves room for Continuation output += o; - pendingOutputs.pop_front(); - currBound = p.end; + pendingOutputs.pop_front(); } // Server indicates that it has more to send, OR ensure client sends a non-empty message