Summary
This PR simplifies and improves the HexDigit initialization logic in src/crypto/hex_base.cpp by:
- Moving the digit lookup table generation into a
constexprhelper function. - Replacing C-style casts with
static_castfor improved type safety and clarity.
Motivation
The previous version repeated the lookup data inline, and used a runtime-initialized static array. This change ensures compile-time initialization via constexpr, which reduces runtime cost and makes the code more readable and testable. It also brings the casting style in line with modern C++ best practices.
Approach
- Introduced a
constexprfunction to generate the hex digit lookup table. - Replaced
reinterpret_cast/C-style casts withstatic_cast<unsigned char>(...).
Testing
- Built successfully on local environment with
make. - All relevant unit tests pass (
make check). - Verified that behavior and memory layout of
HexDigitremain unchanged.
Checklist
- Code compiles
- All tests pass
- Commit message follows conventions
- Clean diff, no unrelated changes
Notes
This is a non-behavioral, low-risk cleanup that improves clarity and performance with modern C++ constructs. Happy to rebase or tweak per review.