From 0de7864755cd5ac746e17851fc8bd0dd06e40703 Mon Sep 17 00:00:00 2001 From: douniwan5788 Date: Mon, 16 Sep 2024 23:17:54 +0800 Subject: [PATCH] refactor: Optimize Dbhexdump --- armsrc/dbprint.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/armsrc/dbprint.c b/armsrc/dbprint.c index eec68ab4ca..42d96fc3ec 100644 --- a/armsrc/dbprint.c +++ b/armsrc/dbprint.c @@ -75,26 +75,27 @@ void Dbprintf(const char *fmt, ...) { // prints HEX & ASCII void Dbhexdump(int len, const uint8_t *d, bool bAsci) { #if DEBUG - char ascii[17]; - while (len > 0) { int l = (len > 16) ? 16 : len; - memcpy(ascii, d, l); - ascii[l] = 0; + if (bAsci) { + char ascii[17]; + + memcpy(ascii, d, l); + ascii[l] = 0; - // filter safe ascii - for (int i = 0; i < l; i++) { - if (ascii[i] < 32 || ascii[i] > 126) { - ascii[i] = '.'; + // filter safe ascii + for (int i = 0; i < l; i++) { + if (ascii[i] < 32 || ascii[i] > 126) { + ascii[i] = '.'; + } } - } - if (bAsci) Dbprintf("%-8s %*D", ascii, l, d, " "); - else + } else { Dbprintf("%*D", l, d, " "); + } len -= 16; d += 16;