From 2529f255554be31582797594d299fb74987bc0df Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?L=C5=91rinc?= Date: Tue, 7 Apr 2026 23:33:49 +0300 Subject: [PATCH] refactor: use `SpanReader` in `PrevectorDeserialize` `PrevectorDeserialize` only needs a reusable read-only view over fixed serialized bytes. Keeping a mutable `DataStream` around just to call `Rewind()` is unnecessary. Rebuild a fresh `SpanReader` for each benchmark run and remove `DataStream::Rewind()`, whose remaining use was this benchmark-only reset path. The benchmark can now serialize exactly the 1000 entries it deserializes, so drop the stale extra element that used to avoid full consumption. Co-authored-by: MarcoFalke <*~=`'#}+{/-|&$^_@721217.xyz> --- src/bench/prevector.cpp | 10 +++++----- src/streams.h | 15 --------------- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/bench/prevector.cpp b/src/bench/prevector.cpp index 8d386ec2c44..e842aec4ed2 100644 --- a/src/bench/prevector.cpp +++ b/src/bench/prevector.cpp @@ -66,22 +66,22 @@ static void PrevectorResize(benchmark::Bench& bench) template static void PrevectorDeserialize(benchmark::Bench& bench) { - DataStream s0{}; + DataStream data{}; prevector t0; t0.resize(CScriptBase::STATIC_SIZE); for (auto x = 0; x < 900; ++x) { - s0 << t0; + data << t0; } t0.resize(100); - for (auto x = 0; x < 101; ++x) { - s0 << t0; + for (auto x = 0; x < 100; ++x) { + data << t0; } bench.batch(1000).run([&] { + SpanReader s0{data}; prevector t1; for (auto x = 0; x < 1000; ++x) { s0 >> t1; } - s0.Rewind(); }); } diff --git a/src/streams.h b/src/streams.h index 4fc5879f67e..6ef9d164494 100644 --- a/src/streams.h +++ b/src/streams.h @@ -206,21 +206,6 @@ public: value_type* data() { return vch.data() + m_read_pos; } const value_type* data() const { return vch.data() + m_read_pos; } - bool Rewind(std::optional n = std::nullopt) - { - // Total rewind if no size is passed - if (!n) { - m_read_pos = 0; - return true; - } - // Rewind by n characters if the buffer hasn't been compacted yet - if (*n > m_read_pos) - return false; - m_read_pos -= *n; - return true; - } - - // // Stream subset //