summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2013-03-06 23:44:23 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2013-03-06 23:44:23 +0100
commit5198ed4bb36e3105a1f12bb3250bee78b6e0dd72 (patch)
tree8b16d7227568b2e1b042cf882876feab9dbed9b9 /util.c
parent76f61bec5e3dea55b2b50f2e8009642977b414e5 (diff)
downloadstrace-5198ed4bb36e3105a1f12bb3250bee78b6e0dd72.tar.gz
strace-5198ed4bb36e3105a1f12bb3250bee78b6e0dd72.tar.bz2
strace-5198ed4bb36e3105a1f12bb3250bee78b6e0dd72.tar.xz
Open-code isprint(c) and isspace(c)
We don't call setlocale, thus we always use C locale. But libc supports various other locales, and therefore its ctype interface is general and at times inefficient. For example, in glibc these macros result in function call, whereas for e.g. isprint(c) just c >= ' ' && c <= 0x7e suffices. By open-coding ctype checks (we have only 4 of them) we avoid function calls, we get smaller code: text data bss dec hex filename 245127 680 5708 251515 3d67b strace_old 245019 676 5708 251403 3d60b strace and we don't link in ctype tables (beneficial for static builds). Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'util.c')
-rw-r--r--util.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/util.c b/util.c
index 0cc43fe..84ab00e 100644
--- a/util.c
+++ b/util.c
@@ -400,7 +400,16 @@ string_quote(const char *instr, char *outstr, long len, int size)
/* Check for NUL-terminated string. */
if (c == eol)
break;
- if (!isprint(c) && !isspace(c)) {
+
+ /* Force hex unless c is printable or whitespace */
+ if (c > 0x7e) {
+ usehex = 1;
+ break;
+ }
+ /* In ASCII isspace is only these chars: "\t\n\v\f\r".
+ * They happen to have ASCII codes 9,10,11,12,13.
+ */
+ if (c < ' ' && (unsigned)(c - 9) >= 5) {
usehex = 1;
break;
}
@@ -453,7 +462,7 @@ string_quote(const char *instr, char *outstr, long len, int size)
*s++ = 'v';
break;
default:
- if (isprint(c))
+ if (c >= ' ' && c <= 0x7e)
*s++ = c;
else {
/* Print \octal */