From ba9560ff029a8e52acc48c8b8741a7f36d12ee25 Mon Sep 17 00:00:00 2001 From: Jim Warner Date: Wed, 13 Jan 2021 00:00:00 -0600 Subject: [PATCH] library: reduce overhead for another 'escape' function The preceding commit made that 'esc_all' function more efficient by using direct pointer manipulation instead of an indexed string reference approach within a loop. This commit applies the same approach to the 'esc_ctl' function. Now we'll save 12 more iterated instructions while decreasing the function's code size by 43 bytes. Signed-off-by: Jim Warner --- proc/escape.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/proc/escape.c b/proc/escape.c index 76be810b..32961a3b 100644 --- a/proc/escape.c +++ b/proc/escape.c @@ -78,13 +78,14 @@ static inline void esc_ctl (unsigned char *str, int len) { for (i = 0; i < len; ) { // even with a proper locale, strings might be corrupt - if ((n = UTF_tab[str[i]]) < 0 || i + n > len) { - esc_all(&str[i]); + if ((n = UTF_tab[*str]) < 0 || i + n > len) { + esc_all(str); return; } // and eliminate those non-printing control characters - if (str[i] < 0x20 || str[i] == 0x7f) - str[i] = '?'; + if (*str < 0x20 || *str == 0x7f) + *str = '?'; + str += n; i += n; } }