ref: f96febf13f98bd4a810267cb6a6f0e26507f41ae
parent: 261ecb5719d526648014a60787a35caaeb2bf593
author: Roberto E. Vargas Caballero <k0ga@shike2.com>
date: Thu Mar 8 14:20:26 EST 2018
[cc2] Rewrite getsym()
--- a/cc2/symbol.c
+++ b/cc2/symbol.c
@@ -64,27 +64,29 @@
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) {
+ htab = &symtab[id & NR_SYMHASH-1];
+ for (sym = *htab; sym; sym = sym->h_next) {
+ if (sym->id == id)
+ return sym;
}
- if (id != TMPSYM) {
- sym->h_next = *htab;
- *htab = 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;
}