aboutsummaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorRichard Henderson <richard.henderson@linaro.org>2024-04-12 00:33:24 -0700
committerRichard Henderson <richard.henderson@linaro.org>2024-06-05 12:14:20 -0700
commit10e4927bc4c5ad673e12c0731e6150050cf327de (patch)
tree1514d4ca1a22694dc33594c1627241614d79ef48 /util
parentc49d1c37d89a2ea994861600859b7dcd3ffa4ede (diff)
downloadqemu-10e4927bc4c5ad673e12c0731e6150050cf327de.zip
qemu-10e4927bc4c5ad673e12c0731e6150050cf327de.tar.gz
qemu-10e4927bc4c5ad673e12c0731e6150050cf327de.tar.bz2
util/hexdump: Inline g_string_append_printf "%02x"
Trivial arithmetic can be used for emitting the nibbles, rather than full-blown printf formatting. Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Reviewed-by: Philippe Mathieu-Daudé <philmd@linaro.org> Message-Id: <20240412073346.458116-6-richard.henderson@linaro.org>
Diffstat (limited to 'util')
-rw-r--r--util/hexdump.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/util/hexdump.c b/util/hexdump.c
index b29326b..ae0d499 100644
--- a/util/hexdump.c
+++ b/util/hexdump.c
@@ -16,6 +16,11 @@
#include "qemu/osdep.h"
#include "qemu/cutils.h"
+static inline char hexdump_nibble(unsigned x)
+{
+ return (x < 10 ? '0' : 'a' - 10) + x;
+}
+
GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len,
size_t unit_len, size_t block_len)
{
@@ -35,6 +40,8 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len,
}
for (u = 0, b = 0; len; u++, b++, len--, buf++) {
+ uint8_t c;
+
if (unit_len && u == unit_len) {
g_string_append_c(str, ' ');
u = 0;
@@ -43,7 +50,10 @@ GString *qemu_hexdump_line(GString *str, const void *vbuf, size_t len,
g_string_append_c(str, ' ');
b = 0;
}
- g_string_append_printf(str, "%02x", *buf);
+
+ c = *buf;
+ g_string_append_c(str, hexdump_nibble(c / 16));
+ g_string_append_c(str, hexdump_nibble(c % 16));
}
return str;