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 <james.warner@comcast.net>
This commit is contained in:
Jim Warner 2021-01-13 00:00:00 -06:00 committed by Craig Small
parent 031a08f2a7
commit ba9560ff02

View File

@ -78,13 +78,14 @@ static inline void esc_ctl (unsigned char *str, int len) {
for (i = 0; i < len; ) { for (i = 0; i < len; ) {
// even with a proper locale, strings might be corrupt // even with a proper locale, strings might be corrupt
if ((n = UTF_tab[str[i]]) < 0 || i + n > len) { if ((n = UTF_tab[*str]) < 0 || i + n > len) {
esc_all(&str[i]); esc_all(str);
return; return;
} }
// and eliminate those non-printing control characters // and eliminate those non-printing control characters
if (str[i] < 0x20 || str[i] == 0x7f) if (*str < 0x20 || *str == 0x7f)
str[i] = '?'; *str = '?';
str += n;
i += n; i += n;
} }
} }