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 <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2012-03-23 11:29:01 +01:00
parent d63b0d5682
commit e4cc7c58dd
2 changed files with 12 additions and 9 deletions

7
defs.h
View File

@ -83,6 +83,13 @@ extern char *stpcpy(char *dst, const char *src);
#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0])) #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 */ /* Configuration section */
#ifndef MAX_QUALS #ifndef MAX_QUALS
# if defined(MIPS) # if defined(MIPS)

View File

@ -337,7 +337,7 @@ qual_syscall(const char *s, int bitflag, int not)
int i; int i;
int rc = -1; int rc = -1;
if (isdigit((unsigned char)*s)) { if (*s >= '0' && *s <= '9') {
int i = atoi(s); int i = atoi(s);
if (i < 0 || i >= MAX_QUALS) if (i < 0 || i >= MAX_QUALS)
return -1; return -1;
@ -373,26 +373,22 @@ static int
qual_signal(const char *s, int bitflag, int not) qual_signal(const char *s, int bitflag, int not)
{ {
int i; int i;
char buf[32];
if (isdigit((unsigned char)*s)) { if (*s >= '0' && *s <= '9') {
int signo = atoi(s); int signo = atoi(s);
if (signo < 0 || signo >= MAX_QUALS) if (signo < 0 || signo >= MAX_QUALS)
return -1; return -1;
qualify_one(signo, bitflag, not, -1); qualify_one(signo, bitflag, not, -1);
return 0; return 0;
} }
if (strlen(s) >= sizeof buf)
return -1;
strcpy(buf, s);
s = buf;
if (strncasecmp(s, "SIG", 3) == 0) if (strncasecmp(s, "SIG", 3) == 0)
s += 3; s += 3;
for (i = 0; i <= NSIG; i++) for (i = 0; i <= NSIG; i++) {
if (strcasecmp(s, signame(i) + 3) == 0) { if (strcasecmp(s, signame(i) + 3) == 0) {
qualify_one(i, bitflag, not, -1); qualify_one(i, bitflag, not, -1);
return 0; return 0;
} }
}
return -1; return -1;
} }
@ -405,7 +401,7 @@ qual_fault(const char *s, int bitflag, int not)
static int static int
qual_desc(const char *s, int bitflag, int not) qual_desc(const char *s, int bitflag, int not)
{ {
if (isdigit((unsigned char)*s)) { if (*s >= '0' && *s <= '9') {
int desc = atoi(s); int desc = atoi(s);
if (desc < 0 || desc >= MAX_QUALS) if (desc < 0 || desc >= MAX_QUALS)
return -1; return -1;