scc

simple c99 compiler
git clone git://git.simple-cc.org/scc
Log | Files | Refs | Submodules | README | LICENSE

commit e163c88706af4d3f68c6f6b04d4980bc14f8f65c
parent 6a6fc18fa4b061ae0389c370d7c416f17a883761
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 12 Feb 2024 08:59:24 +0100

as: Simplify lookup

Diffstat:
Msrc/cmd/as/symbol.c | 27+++++++++++----------------
1 file changed, 11 insertions(+), 16 deletions(-)

diff --git a/src/cmd/as/symbol.c b/src/cmd/as/symbol.c @@ -61,37 +61,32 @@ dumpstab(char *msg) Symbol * lookup(char *name) { + int r; unsigned h; Symbol *sym; - int r, c, symtype; - struct lsymbol *lp, **list; - char *t, buf[INTIDENTSIZ+1]; + struct lsymbol *lp; + char *curname, buf[INTIDENTSIZ+1]; if (*name == '.' && cursym) { if (!cursym) error("local label '%s' without global label", name); - t = cursym->name; - r = snprintf(buf, sizeof(buf), "%s%s", t, name); + curname = cursym->name; + r = snprintf(buf, sizeof(buf), "%s%s", curname, name); if (r < 0 || r >= sizeof(buf)) - error("too long local label '%s%s'", t, name); + error("too long local label '%s%s'", curname, name); name = buf; } h = genhash(name) & HASHSIZ-1; - - c = toupper(*name); - list = &hashtbl[h]; - for (lp = *list; lp; lp = lp->hash) { - sym = &lp->sym; - t = lp->sym.name; - if (c == toupper(*t) && !casecmp(t, name)) - return sym; + for (lp = hashtbl[h]; lp; lp = lp->hash) { + if (!casecmp(lp->sym.name, name)) + return &lp->sym; } lp = xmalloc(sizeof(*lp)); lp->next = NULL; - lp->hash = *list; - *list = lp; + lp->hash = hashtbl[h]; + hashtbl[h] = lp; if (symlast) symlast->next = lp;