ref: 4d2efcd9e1fb32a723e0ed9222c12d07cf782f0b
parent: 24e2f336e79216f6c8d91a74eb4cdf88a5749434
author: Roberto E. Vargas Caballero <[email protected]>
date: Tue Sep 26 06:56:48 EDT 2017
[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.
--- 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 @@
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
--- a/as/symbol.c
+++ b/as/symbol.c
@@ -56,11 +56,11 @@
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;
}