diff options
author | m-holger <m-holger@kubitscheck.org> | 2022-09-22 21:13:51 +0200 |
---|---|---|
committer | Jay Berkenbilt <jberkenbilt@users.noreply.github.com> | 2022-09-23 12:20:12 +0200 |
commit | ae800361fefb6d30d054f5d90af310c85765b044 (patch) | |
tree | 5b09b6c64ed531845a80931d826adcff19671143 /libqpdf | |
parent | 033a66e9a5f859798cfc1920eb3129b40fdaa842 (diff) | |
download | qpdf-ae800361fefb6d30d054f5d90af310c85765b044.tar.zst |
Tune QUtil::hex_encode
Diffstat (limited to 'libqpdf')
-rw-r--r-- | libqpdf/QUtil.cc | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/libqpdf/QUtil.cc b/libqpdf/QUtil.cc index 98a8f318..bcf4aa4e 100644 --- a/libqpdf/QUtil.cc +++ b/libqpdf/QUtil.cc @@ -769,10 +769,12 @@ QUtil::make_unique_cstr(std::string const& str) std::string QUtil::hex_encode(std::string const& input) { + static auto constexpr hexchars = "0123456789abcdef"; std::string result; - for (unsigned int i = 0; i < input.length(); ++i) { - result += QUtil::int_to_string_base( - QIntC::to_int(static_cast<unsigned char>(input.at(i))), 16, 2); + result.reserve(2 * input.length()); + for (const char c: input) { + result += hexchars[static_cast<unsigned char>(c) >> 4]; + result += hexchars[c & 0x0f]; } return result; } |