The original code is doing a modulus operation for every character, which is often orders of magnitude slower than the byte comparision or addition/subtraction.
Move the expensive operation out of the loop.
Note that a simpler version of this fix ended up yielding worse performances on ARM Mac architectures, hence the switch to `std::find` (see https://github.com/bitcoin/bitcoin/pull/19690#pullrequestreview-1318324998)
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This concludes backport of [[https://github.com/bitcoin/bitcoin/pull/19690 | core#19690]]
https://github.com/bitcoin/bitcoin/pull/19690/commits/72efc26439da9a1344a19569fb0cab01f82ae7d1
Depends on D16179