From ae800361fefb6d30d054f5d90af310c85765b044 Mon Sep 17 00:00:00 2001
From: m-holger <m-holger@kubitscheck.org>
Date: Thu, 22 Sep 2022 20:13:51 +0100
Subject: [PATCH] Tune QUtil::hex_encode

Reference: https://github.com/qpdf/qpdf/commit/ae800361fefb6d30d054f5d90af310c85765b044
---
 libqpdf/QUtil.cc | 8 +++++---
 1 file 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;
 }
-- 
2.39.3

