scc

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

commit e11576874bba09ca8d7e52be405c9c29518b49bd
parent 1c450f351d049e620d63b4dd9ad7acc0bc6f0ed3
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Sun,  9 Mar 2014 16:03:56 +0100

Optimize the search of keywords

It is difficult two strings with the same hash and the same initial
letter, so this test save a lot of calls to strcmp.

Diffstat:
Mlex.c | 4++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/lex.c b/lex.c @@ -170,12 +170,12 @@ init_keywords(void) } static unsigned char -keyword(char *s) +keyword(register char *s) { register struct keyword *bp; for (bp = ktab[hash(s) & NR_KEYW_HASH-1]; bp; bp = bp->next) { - if (!strcmp(bp->str, s)) + if (*s == *bp->str && !strcmp(bp->str, s)) return bp->tok; } return 0;