scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit 73b75c89b315cc6f97f8d9fc431e84bf1a002d3a
parent 11a557fc44cb50172c5ae35b701a35e4265b1a35
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu, 28 Sep 2017 08:48:19 +0100

[as] Don't use casecmp with bsearch()

We can convert to upper case the verb before begin
to compare. It will make faster all the comparisions
that is where the time will be consumed.

Diffstat:
Mas/main.c | 10+++++++---
1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/as/main.c b/as/main.c @@ -15,20 +15,24 @@ cmp(const void *f1, const void *f2) const char *s = f1; int d; - d = toupper(*ins->str) - toupper(*s); - if (d != 0) + if ((d = *s - *ins->str) != 0) return d; - return casecmp(s, ins->str); + return strcmp(s, ins->str); } static void as(char *text, char *xargs) { + int c; + char *p; Ins *ins; Op *op, *lim; Node **args; + for (p = text; c = *p; ++p) + *p = toupper(c); + ins = bsearch(text, instab, nr_ins, sizeof(Ins), cmp); if (!ins) { error("invalid instruction");