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>
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;
}
}