From e4cc7c58dda80d502e5c66c0c91f7df191d540a8 Mon Sep 17 00:00:00 2001 From: Denys Vlasenko Date: Fri, 23 Mar 2012 11:29:01 +0100 Subject: [PATCH] Simple optimizations Why open-coding isdigit is a good idea? Before: call __ctype_b_loc movzbl (%ebx),%edx mov (%eax),%eax testb $0x8,0x1(%eax,%edx,2) je lbl After: movzbl (%eax),%edx sub $0x30,%edx cmp $0x9,%dl ja lbl text data bss dec hex filename 236869 704 18944 256517 3ea05 strace.before 236719 700 18944 256363 3e96b strace * defs.h: Alias sigemptyset to __sigemptyset on glibc. * syscall.c (qual_syscall): Open-code isdigit. (qual_desc): Likewise. (qual_signal): Open-code isdigit. Remove string copying which was done for no apparent reason. Signed-off-by: Denys Vlasenko --- defs.h | 7 +++++++ syscall.c | 14 +++++--------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/defs.h b/defs.h index a0445c3f..e46e230a 100644 --- a/defs.h +++ b/defs.h @@ -83,6 +83,13 @@ extern char *stpcpy(char *dst, const char *src); #define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) +/* Glibc has an efficient macro for sigemptyset + * (it just does one or two assignments of 0 to internal vector of longs). + */ +#if defined(__GLIBC__) && defined(__sigemptyset) && !defined(sigemptyset) +# define sigemptyset __sigemptyset +#endif + /* Configuration section */ #ifndef MAX_QUALS # if defined(MIPS) diff --git a/syscall.c b/syscall.c index 663d678b..c4ac9778 100644 --- a/syscall.c +++ b/syscall.c @@ -337,7 +337,7 @@ qual_syscall(const char *s, int bitflag, int not) int i; int rc = -1; - if (isdigit((unsigned char)*s)) { + if (*s >= '0' && *s <= '9') { int i = atoi(s); if (i < 0 || i >= MAX_QUALS) return -1; @@ -373,26 +373,22 @@ static int qual_signal(const char *s, int bitflag, int not) { int i; - char buf[32]; - if (isdigit((unsigned char)*s)) { + if (*s >= '0' && *s <= '9') { int signo = atoi(s); if (signo < 0 || signo >= MAX_QUALS) return -1; qualify_one(signo, bitflag, not, -1); return 0; } - if (strlen(s) >= sizeof buf) - return -1; - strcpy(buf, s); - s = buf; if (strncasecmp(s, "SIG", 3) == 0) s += 3; - for (i = 0; i <= NSIG; i++) + for (i = 0; i <= NSIG; i++) { if (strcasecmp(s, signame(i) + 3) == 0) { qualify_one(i, bitflag, not, -1); return 0; } + } return -1; } @@ -405,7 +401,7 @@ qual_fault(const char *s, int bitflag, int not) static int qual_desc(const char *s, int bitflag, int not) { - if (isdigit((unsigned char)*s)) { + if (*s >= '0' && *s <= '9') { int desc = atoi(s); if (desc < 0 || desc >= MAX_QUALS) return -1;