Was having issues with inefficient MSVC code-generation and also for a time was trying to make it constexpr instead of consteval and missing static constexpr from C++23. It's doable under consteval but the diff ain't too pretty:
diff --git a/src/uint256.h b/src/uint256.h
index a52b0a1f71..be27be93de 100644
--- a/src/uint256.h
+++ b/src/uint256.h
@@ -98,18 +98,35 @@ consteval base_blob<BITS>::base_blob(std::string_view hex_str)
{
// Non-lookup table version of HexDigit().
auto from_hex = [](const char c) -> int8_t {
- if (c >= '0' && c <= '9') return c - '0';
- if (c >= 'a' && c <= 'f') return c - 'a' + 0xA;
- if (c >= 'A' && c <= 'F') return c - 'A' + 0xA;
-
- assert(false); // Reached if ctor is called with an invalid hex digit.
+ constexpr signed char hexdigit[256] =
+ { -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ 0,1,2,3,4,5,6,7,8,9,-1,-1,-1,-1,-1,-1,
+ -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,0xa,0xb,0xc,0xd,0xe,0xf,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,
+ -1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1,-1, };
+
+ return hexdigit[(uint8_t)c];
};
assert(hex_str.length() == m_data.size() * 2); // 2 hex digits per byte.
auto str_it = hex_str.rbegin();
for (auto& elem : m_data) {
auto lo = from_hex(*(str_it++));
- elem = (from_hex(*(str_it++)) << 4) | lo;
+ assert(lo != -1);
+ auto hi = from_hex(*(str_it++));
+ assert(hi != -1);
+ elem = (hi << 4) | lo;
}
}
Depending on compile time measurement results, I'll reconsider this.