scc

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

commit 5adb9664d4c43d1f155907fc8c7abdc50750b6f1
parent 2ed9319063abaddf86c95e0bfa0247b24674ca94
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Thu,  8 Mar 2018 19:20:26 +0100

[cc2] Rewrite getsym()

Diffstat:
Mcc2/symbol.c | 42++++++++++++++++++++++--------------------
1 file changed, 22 insertions(+), 20 deletions(-)

diff --git a/cc2/symbol.c b/cc2/symbol.c @@ -64,27 +64,29 @@ getsym(unsigned id) if (id >= USHRT_MAX) error(EBADID); - htab = &symtab[id & NR_SYMHASH-1]; - for (sym = *htab; sym; sym = sym->h_next) { - if (sym->id > 0 && sym->id == id) - break; - } - if (!sym) { - sym = xcalloc(1, sizeof(*sym)); - sym->id = id; - if ((sym->numid = ++num) == 0) - error(EIDOVER); - if (infunction) { - if (!locals) - locals = sym; - if (curlocal) - curlocal->next = sym; - curlocal = sym; - } - if (id != TMPSYM) { - sym->h_next = *htab; - *htab = sym; + if (id != TMPSYM) { + htab = &symtab[id & NR_SYMHASH-1]; + for (sym = *htab; sym; sym = sym->h_next) { + if (sym->id == id) + return sym; } } + + sym = xcalloc(1, sizeof(*sym)); + sym->id = id; + if (infunction) { + if (!locals) + locals = sym; + if (curlocal) + curlocal->next = sym; + curlocal = sym; + } + if (id != TMPSYM) { + sym->h_next = *htab; + *htab = sym; + } + if ((sym->numid = ++num) == 0) + error(EIDOVER); + return sym; }