Hi,
This is kinda chasing Concept ACK if it’s worth the review effort.* (noticed it while reviewing a PR)
Right now both DecodeBase32 and DecodeBase64 are only ever being called with std::string
but still process via char*
and so they run strlen
(O(n)) twice, once to validate it doesn’t contain random zeros(ValidAsCString
) another to get the length.
Instead we can iterate it as a std::string and then if we see 0
in the middle of the string we can fail the process.
* if it is, there’s also DecodeBase58 .
And as a by-product saw 2 other places where we can pre-allocate memory.
EDIT: So the by-product turned out to be the only interesting part of this PR :) (see #18061 (comment)) According to the benchmarks this can cut the time it takes to parse a hex by half.