]> granicus.if.org Git - procps-ng/commitdiff
library: reduce overhead for another 'escape' function
authorJim Warner <james.warner@comcast.net>
Wed, 13 Jan 2021 06:00:00 +0000 (00:00 -0600)
committerCraig Small <csmall@dropbear.xyz>
Thu, 21 Jan 2021 06:30:24 +0000 (17:30 +1100)
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 <james.warner@comcast.net>
proc/escape.c

index 76be810b5c38d5b44e43a3ef7053a435638a3b1f..32961a3b04b8caf19ca9013a842b88e685c78c81 100644 (file)
@@ -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;
    }
 }