Commit ae800361fefb6d30d054f5d90af310c85765b044

Authored by m-holger
Committed by Jay Berkenbilt
1 parent 033a66e9

Tune QUtil::hex_encode

Showing 1 changed file with 5 additions and 3 deletions
libqpdf/QUtil.cc
... ... @@ -769,10 +769,12 @@ QUtil::make_unique_cstr(std::string const& str)
769 769 std::string
770 770 QUtil::hex_encode(std::string const& input)
771 771 {
  772 + static auto constexpr hexchars = "0123456789abcdef";
772 773 std::string result;
773   - for (unsigned int i = 0; i < input.length(); ++i) {
774   - result += QUtil::int_to_string_base(
775   - QIntC::to_int(static_cast<unsigned char>(input.at(i))), 16, 2);
  774 + result.reserve(2 * input.length());
  775 + for (const char c: input) {
  776 + result += hexchars[static_cast<unsigned char>(c) >> 4];
  777 + result += hexchars[c & 0x0f];
776 778 }
777 779 return result;
778 780 }
... ...