mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-01-20 23:29:12 +01:00
refactor: Add consteval uint256(hex_str)
Complements uint256::FromHex() nicely in that it naturally does all error checking at compile time and so doesn't need to return an std::optional. Will be used in the following 2 commits to replace many calls to uint256S(). uint256S() calls taking C-string literals are littered throughout the codebase and executed at runtime to perform parsing unless a given optimizer was surprisingly efficient. While this may not be a hot spot, it's better hygiene in C++20 to store the parsed data blob directly in the binary, without any parsing at runtime.
This commit is contained in:
@@ -399,4 +399,11 @@ BOOST_AUTO_TEST_CASE( check_ONE )
|
||||
BOOST_CHECK_EQUAL(one, uint256::ONE);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(FromHex_vs_uint256)
|
||||
{
|
||||
auto runtime_uint{uint256::FromHex("4A5E1E4BAAB89F3A32518A88C31BC87F618f76673e2cc77ab2127b7afdeda33b").value()};
|
||||
constexpr uint256 consteval_uint{ "4a5e1e4baab89f3a32518a88c31bc87f618F76673E2CC77AB2127B7AFDEDA33B"};
|
||||
BOOST_CHECK_EQUAL(consteval_uint, runtime_uint);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_SUITE_END()
|
||||
|
||||
Reference in New Issue
Block a user