commit 86648da0334bde1671813c6906d74ce8508ead5d
parent 05daa1d657c80dba6a7a3ea38ef9d94ac8d718e8
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Tue, 26 Sep 2017 10:56:48 +0100
[as] Reduce the number of calls to casecmp()
In both cases the common case is to have a different first letter,
so this small optimize improves a lot the performance in both cases.
Diffstat:
2 files changed, 10 insertions(+), 3 deletions(-)
diff --git a/as/main.c b/as/main.c
@@ -1,5 +1,6 @@
static char sccsid[] = "@(#) ./as/main.c";
+#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@@ -17,8 +18,14 @@ static int
cmp(const void *f1, const void *f2)
{
const Ins *ins = f2;
+ const char *s = f1;
+ int d;
- return casecmp(f1, ins->str);
+ d = toupper(*ins->str) - toupper(*s);
+ if (d != 0)
+ return d;
+
+ return casecmp(s, ins->str);
}
static void
diff --git a/as/symbol.c b/as/symbol.c
@@ -56,11 +56,11 @@ lookup(char *name)
h = h*33 ^ c;
h &= HASHSIZ-1;
- c = *name;
+ c = toupper(*name);
list = &hashtbl[h];
for (sym = *list; sym; sym = sym->next) {
t = sym->name;
- if (c == *t && !casecmp(t, name))
+ if (c == toupper(*t) && !casecmp(t, name))
return sym;
}