]> granicus.if.org Git - strace/commitdiff
Simple optimizations
authorDenys Vlasenko <vda.linux@googlemail.com>
Fri, 23 Mar 2012 10:29:01 +0000 (11:29 +0100)
committerDenys Vlasenko <vda.linux@googlemail.com>
Fri, 23 Mar 2012 10:29:01 +0000 (11:29 +0100)
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>
defs.h
syscall.c

diff --git a/defs.h b/defs.h
index a0445c3f7ffaf54b1c771fafb2c177c98f036fb5..e46e230a544f7f597fabeeb194358b62b3dc3ba4 100644 (file)
--- 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)
index 663d678b841608cfb6085fad8e750f8d38c675fb..c4ac9778e08d93e484972284550660fedc159326 100644 (file)
--- 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;