Skip to content

Commit 2530a24

Browse files
committed
Merge bitcoin/bitcoin#26105: Use ReadLE64 in uint256::GetUint64 instead of duplicating logic
04fee75 Use ReadLE64 in uint256::GetUint64() instead of duplicating logic (Pieter Wuille) Pull request description: No need to have a (naive) copy of the `ReadLE64` logic inside `uint256::GetUint64`, when we have an optimized function for exactly that. ACKs for top commit: davidgumberg: ACK 04fee75 jonatack: ACK 04fee75 review, this use of ReadLE64() is similar to the existing invocation by Num3072::Num3072(), sanity checked that before and after this change GetUint64() returns the same result (debug build, clang 13) Tree-SHA512: 0fc2681536a18d82408411bcc6d5c6445fb96793fa43ff4021cd2933d46514c725318da35884f428d1799023921f33f8af091ef428ceb96a50866ac53a345356
2 parents 19526d9 + 04fee75 commit 2530a24

File tree

1 file changed

+2
-9
lines changed

1 file changed

+2
-9
lines changed

src/uint256.h

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#ifndef BITCOIN_UINT256_H
77
#define BITCOIN_UINT256_H
88

9+
#include <crypto/common.h>
910
#include <span.h>
1011

1112
#include <assert.h>
@@ -84,15 +85,7 @@ class base_blob
8485

8586
uint64_t GetUint64(int pos) const
8687
{
87-
const uint8_t* ptr = m_data + pos * 8;
88-
return ((uint64_t)ptr[0]) | \
89-
((uint64_t)ptr[1]) << 8 | \
90-
((uint64_t)ptr[2]) << 16 | \
91-
((uint64_t)ptr[3]) << 24 | \
92-
((uint64_t)ptr[4]) << 32 | \
93-
((uint64_t)ptr[5]) << 40 | \
94-
((uint64_t)ptr[6]) << 48 | \
95-
((uint64_t)ptr[7]) << 56;
88+
return ReadLE64(m_data + pos * 8);
9689
}
9790

9891
template<typename Stream>

0 commit comments

Comments
 (0)