[hackers] [scc] Avoid doble call to hash() in lookup() || Roberto E. Vargas Caballero
X-DEBUG-UPD: ac748964eb6c3535320d3bedc211a4e272cf946f
commit ac748964eb6c3535320d3bedc211a4e272cf946f
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Tue Aug 18 14:24:12 2015 +0200
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Tue Aug 18 14:24:12 2015 +0200
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().
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 5738d2e..e2e7e0f 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -55,12 +55,12 @@ hash(const char *s)
}
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)
_AT_@ -204,10 +204,11 @@ Symbol *
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;
_AT_@ -220,7 +221,7 @@ lookup(unsigned ns)
continue;
return sym;
}
- sym = linkhash(newsym(ns), yytext);
+ sym = linkhash(newsym(ns), yytext, v);
sym->flags &= ~ISDECLARED;
return sym;
_AT_@ -254,7 +255,7 @@ nextsym(Symbol *sym, unsigned ns)
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;
}
_AT_@ -272,7 +273,7 @@ install(unsigned ns, Symbol *sym)
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)
Received on Fri Aug 21 2015 - 13:10:37 CEST
This archive was generated by hypermail 2.3.0
: Fri Aug 21 2015 - 13:12:18 CEST