Skip to content

Commit 6c93cd2

Browse files
authored
Merge pull request #1396 from AntelopeIO/merkle_c++20_ifdefs_remove
remove C++20 ifdefs in merkle.hpp
2 parents 87738bd + fd4ce84 commit 6c93cd2

2 files changed

Lines changed: 4 additions & 16 deletions

File tree

libraries/chain/include/eosio/chain/incremental_merkle.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,9 @@ namespace eosio::chain {
3131
class incremental_merkle_tree {
3232
public:
3333
void append(const digest_type& digest) {
34-
assert(trees.size() == static_cast<size_t>(detail::popcount(mask)));
34+
assert(trees.size() == static_cast<size_t>(std::popcount(mask)));
3535
_append(digest, trees.end(), 0);
36-
assert(trees.size() == static_cast<size_t>(detail::popcount(mask)));
36+
assert(trees.size() == static_cast<size_t>(std::popcount(mask)));
3737
}
3838

3939
digest_type get_root() const {

libraries/chain/include/eosio/chain/merkle.hpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,6 @@ namespace eosio::chain {
99

1010
namespace detail {
1111

12-
#if __cplusplus >= 202002L
13-
inline int popcount(uint64_t x) noexcept { return std::popcount(x); }
14-
inline uint64_t bit_floor(uint64_t x) noexcept { return std::bit_floor(x); }
15-
#else
16-
inline int popcount(uint64_t x) noexcept { return __builtin_popcountll(x); }
17-
inline uint64_t bit_floor(uint64_t x) noexcept { return x == 0 ? 0ull : 1ull << (64 - 1 - __builtin_clzll(x)); }
18-
#endif
19-
2012
inline digest_type hash_combine(const digest_type& a, const digest_type& b) {
2113
return digest_type::hash(std::make_pair(std::cref(a), std::cref(b)));
2214
}
@@ -26,7 +18,7 @@ requires std::is_same_v<std::decay_t<typename std::iterator_traits<It>::value_ty
2618
inline digest_type calculate_merkle_pow2(const It& start, const It& end) {
2719
assert(end >= start + 2);
2820
auto size = static_cast<size_t>(end - start);
29-
assert(detail::bit_floor(size) == size);
21+
assert(std::bit_floor(size) == size);
3022

3123
if (size == 2)
3224
return hash_combine(start[0], start[1]);
@@ -76,17 +68,15 @@ inline digest_type calculate_merkle_pow2(const It& start, const It& end) {
7668
// appended (or 0.25% of default 2MB thread stack size on Ubuntu).
7769
// ------------------------------------------------------------------------
7870
template <class It>
79-
#if __cplusplus >= 202002L
8071
requires std::random_access_iterator<It> &&
8172
std::is_same_v<std::decay_t<typename std::iterator_traits<It>::value_type>, digest_type>
82-
#endif
8373
inline digest_type calculate_merkle(const It& start, const It& end) {
8474
assert(end >= start);
8575
auto size = static_cast<size_t>(end - start);
8676
if (size <= 1)
8777
return (size == 0) ? digest_type{} : *start;
8878

89-
auto midpoint = detail::bit_floor(size);
79+
auto midpoint = std::bit_floor(size);
9080
if (size == midpoint)
9181
return detail::calculate_merkle_pow2<It, true>(start, end);
9282

@@ -102,10 +92,8 @@ inline digest_type calculate_merkle(const It& start, const It& end) {
10292
// for the sequence of digests in the container.
10393
// --------------------------------------------------------------------------
10494
template <class Cont>
105-
#if __cplusplus >= 202002L
10695
requires std::random_access_iterator<decltype(Cont().begin())> &&
10796
std::is_same_v<std::decay_t<typename Cont::value_type>, digest_type>
108-
#endif
10997
inline digest_type calculate_merkle(const Cont& ids) {
11098
return calculate_merkle(ids.begin(), ids.end()); // cbegin not supported for std::span until C++23.
11199
}

0 commit comments

Comments
 (0)