From 0f9f3a0834b0f72522a4a9a6d19b65d0f934908b Mon Sep 17 00:00:00 2001 From: JCW Date: Thu, 22 May 2025 08:34:43 +0100 Subject: [PATCH] update --- include/xrpl/beast/hash/xxhasher.h | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/include/xrpl/beast/hash/xxhasher.h b/include/xrpl/beast/hash/xxhasher.h index 4507b3efda..43a9ac2f49 100644 --- a/include/xrpl/beast/hash/xxhasher.h +++ b/include/xrpl/beast/hash/xxhasher.h @@ -28,6 +28,7 @@ #include #include #include +#include namespace beast { @@ -39,6 +40,11 @@ private: XXH3_state_t* state_; + std::array buffer_; + std::span readSpan_; + std::span writeSpan_; + XXH64_hash_t seed_{}; + static XXH3_state_t* allocState() { @@ -61,6 +67,7 @@ public: { state_ = allocState(); XXH3_64bits_reset(state_); + writeSpan_ = buffer_; } ~xxhasher() noexcept @@ -75,6 +82,7 @@ public: { state_ = allocState(); XXH3_64bits_reset_withSeed(state_, seed); + seed_ = seed; } template < @@ -84,20 +92,30 @@ public: { state_ = allocState(); XXH3_64bits_reset_withSeed(state_, seed); + seed_ = seed; } void operator()(void const* key, std::size_t len) noexcept { FunctionProfiler _{"-size-" + std::to_string(len)}; - XXH3_64bits_update(state_, key, len); + //XXH3_64bits_update(state_, key, len); + if (len >= writeSpan_.size()) + { + exit(-1); + } + std::memcpy(writeSpan_.data(), key, len); + writeSpan_ = writeSpan_.subspan(len); + readSpan_ = std::span(std::begin(buffer_), readSpan_.size() + len); } explicit operator std::size_t() noexcept { FunctionProfiler _{"-digest"}; - return XXH3_64bits_digest(state_); + // XXH3_64bits_update(state_, readSpan_.data(), readSpan_.size()); + // return XXH3_64bits_digest(state_); + return XXH64(readSpan_.data(), readSpan_.size(), seed_); } };