Skip to content

Commit

Permalink
avoid unnecessary memcpy
Browse files Browse the repository at this point in the history
  • Loading branch information
greenaddress committed May 15, 2024
1 parent 5a52c67 commit cf9e6b9
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 6 deletions.
4 changes: 1 addition & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,8 @@ using namespace std;

namespace ur {

ByteVector sha256(const ByteVector &buf) {
array<uint8_t,SHA256_DIGEST_LENGTH> digest;
void sha256(const ByteVector &buf, std::array<uint8_t, SHA256_DIGEST_LENGTH> &digest) {
sha256_Raw(buf.data(), buf.size(), digest.data());
return {digest.begin(), digest.end()};
}

ByteVector crc32_bytes(const ByteVector &buf) {
Expand Down
2 changes: 1 addition & 1 deletion src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ namespace ur {
using ByteVector = std::vector<uint8_t>;
using StringVector = std::vector<std::string>;

ByteVector sha256(const ByteVector &buf);
void sha256(const ByteVector &buf, std::array<uint8_t, 32> &digest);
ByteVector crc32_bytes(const ByteVector &buf);
uint32_t crc32_int(const ByteVector &buf);

Expand Down
3 changes: 1 addition & 2 deletions src/xoshiro256.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,8 @@ void Xoshiro256::set_s(const std::array<uint8_t, 32>& a) {
}

void Xoshiro256::hash_then_set_s(const ByteVector& bytes) {
auto digest = sha256(bytes);
std::array<uint8_t, 32> a;
memcpy(a.data(), &digest[0], 32);
sha256(bytes, a);
set_s(a);
}

Expand Down

0 comments on commit cf9e6b9

Please sign in to comment.