From cf9e6b932e3ecef9b2c96865174c45ce2b32b394 Mon Sep 17 00:00:00 2001 From: Lawrence Nahum Date: Wed, 15 May 2024 13:39:17 +0200 Subject: [PATCH] avoid unnecessary memcpy --- src/utils.cpp | 4 +--- src/utils.hpp | 2 +- src/xoshiro256.cpp | 3 +-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 23de7c3..8e5669f 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -24,10 +24,8 @@ using namespace std; namespace ur { -ByteVector sha256(const ByteVector &buf) { - array digest; +void sha256(const ByteVector &buf, std::array &digest) { sha256_Raw(buf.data(), buf.size(), digest.data()); - return {digest.begin(), digest.end()}; } ByteVector crc32_bytes(const ByteVector &buf) { diff --git a/src/utils.hpp b/src/utils.hpp index e362828..1a74f45 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -20,7 +20,7 @@ namespace ur { using ByteVector = std::vector; using StringVector = std::vector; -ByteVector sha256(const ByteVector &buf); +void sha256(const ByteVector &buf, std::array &digest); ByteVector crc32_bytes(const ByteVector &buf); uint32_t crc32_int(const ByteVector &buf); diff --git a/src/xoshiro256.cpp b/src/xoshiro256.cpp index 58b589f..fa91ab0 100644 --- a/src/xoshiro256.cpp +++ b/src/xoshiro256.cpp @@ -54,9 +54,8 @@ void Xoshiro256::set_s(const std::array& a) { } void Xoshiro256::hash_then_set_s(const ByteVector& bytes) { - auto digest = sha256(bytes); std::array a; - memcpy(a.data(), &digest[0], 32); + sha256(bytes, a); set_s(a); }