scc

simple C compiler
git clone git://git.2f30.org/scc
Log | Files | Refs | README | LICENSE

commit e337843c58d1d5b0e91134c6d3173c97708cb291
parent 9c3251a4af2a09de43b0745569f011101cc5246e
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date:   Mon, 20 Feb 2017 08:43:54 +0100

[cc1] Move labels to a different hash table

Diffstat:
Mcc1/symbol.c | 25++++++++++++++++++++-----
1 file changed, 20 insertions(+), 5 deletions(-)

diff --git a/cc1/symbol.c b/cc1/symbol.c @@ -11,13 +11,16 @@ static char sccsid[] = "@(#) ./cc1/symbol.c"; #include "cc1.h" #define NR_SYM_HASH 64 +#define NR_CPP_HASH 32 +#define NR_LBL_HASH 16 unsigned curctx; static unsigned short counterid; static Symbol *head, *labels; static Symbol *htab[NR_SYM_HASH]; -static Symbol *htabcpp[NR_SYM_HASH]; +static Symbol *htabcpp[NR_CPP_HASH]; +static Symbol *htablbl[NR_LBL_HASH]; #ifndef NDEBUG void @@ -54,15 +57,27 @@ dumpstab(Symbol **tbl, char *msg) static Symbol ** hash(char *s, int ns) { - unsigned c, h; + unsigned c, h, size; Symbol **tab; for (h = 0; c = *s; ++s) h = h*33 ^ c; - h &= NR_SYM_HASH-1; - tab = (ns == NS_CPP) ? htabcpp : htab; - return &tab[h]; + switch (ns) { + case NS_CPP: + tab = htabcpp; + size = NR_CPP_HASH-1; + break; + case NS_LABEL: + tab = htablbl; + size = NR_LBL_HASH-1; + break; + default: + tab = htab; + size = NR_SYM_HASH-1; + break; + } + return &tab[h & size]; } static void