ref: ac748964eb6c3535320d3bedc211a4e272cf946f
parent: 1ea33a55b6d3df7fd73194f0f2a599960c67676e
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Tue Aug 18 10:24:12 EDT 2015
Avoid doble call to hash() in lookup() It is better to pass the hash value to linkhash instead of calling to lookup all the times inside of linkhash().
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
@@ -55,12 +55,12 @@
}
static Symbol *
-linkhash(Symbol *sym, char *name)
+linkhash(Symbol *sym, char *name, unsigned hval)
{
Symbol **h, *p, *prev;
sym->name = xstrdup(name);
- h = &htab[hash(name)];
+ h = &htab[hval];
for (prev = p = *h; p; prev = p, p = p->hash) {
if (p->ctx <= sym->ctx)
@@ -204,10 +204,11 @@
lookup(unsigned ns)
{
Symbol *sym, **h;
- unsigned sns;
+ unsigned sns, v;
char *t, c;
- h = &htab[hash(yytext)];
+ v = hash(yytext);
+ h = &htab[v];
c = *yytext;
for (sym = *h; sym; sym = sym->hash) {
t = sym->name;
@@ -220,7 +221,7 @@
continue;
return sym;
}
- sym = linkhash(newsym(ns), yytext);
+ sym = linkhash(newsym(ns), yytext, v);
sym->flags &= ~ISDECLARED;
return sym;
@@ -254,7 +255,7 @@
if (c == *t && !strcmp(s, t))
return sym;
}
- new = linkhash(newsym(ns), s);
+ new = linkhash(newsym(ns), s, hash(s));
new->flags &= ~ISDECLARED;
return new;
}
@@ -272,7 +273,7 @@
goto assign_id;
}
}
- sym = linkhash(newsym(ns), sym->name);
+ sym = linkhash(newsym(ns), sym->name, hash(sym->name));
assign_id:
if (sym->ns != NS_CPP || sym->ns != NS_LABEL)