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. Use `std::find` instead of scanning each byte. No functional difference.
Co-authored-by: Hennadii Stepanov <32963518+hebasto@users.noreply.github.com>
This concludes backport of core#19690
https://github.com/bitcoin/bitcoin/pull/19690/commits/72efc26439da9a1344a19569fb0cab01f82ae7d1
Depends on D16179