Make use of std::string_view
and std::optional
in the util/{strencodings, string} files.
This avoids many temporary string/vector objects being created, while making the interface easier to read. Changes include:
- Make all input arguments in functions in util/strencodings and util/string take
std::string_view
instead ofstd::string
. - Add
RemovePrefixView
andTrimStringView
which also returnstd::string_view
objects (the correspondingRemovePrefix
andTrimString
keep returning anstd::string
, as that’s needed in many call sites still). - Stop returning
std::string
fromDecodeBase32
andDecodeBase64
, but return vectors. Base32/64 are fundamentally algorithms for encoding bytes as strings; returningstd::string
from those (especially doing it conditionally based on the input arguments/types) is just bizarre. - Stop taking a
bool* pf_invalid
output argument pointer inDecodeBase32
andDecodeBase64
; return anstd::optional
instead. - Make
DecodeBase32
andDecodeBase64
more efficient by doing the conversion from characters to integer symbols on-the-fly rather than through a temporary vector.