[hackers] [scc] [cc1] Centralize hash selection || Roberto E. Vargas Caballero
commit ca6f77982f0907933243c0fc585c34acf3d59c62
Author: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
AuthorDate: Thu Dec 22 15:50:06 2016 +0100
Commit: Roberto E. Vargas Caballero <k0ga_AT_shike2.com>
CommitDate: Thu Dec 22 15:50:06 2016 +0100
[cc1] Centralize hash selection
We have several hash tables now, and it is not a good idea to
repeat the selection code everywhere. Hash() is going to be the
function which returns a pointer to the bucket position in the
hash table.
diff --git a/cc1/symbol.c b/cc1/symbol.c
index 9f67694..9374874 100644
--- a/cc1/symbol.c
+++ b/cc1/symbol.c
_AT_@ -44,25 +44,29 @@ dumpstab(char *msg)
}
#endif
-static unsigned
-hash(const char *s)
+static Symbol **
+hash(const char *s, int ns)
{
unsigned c, h;
+ Symbol **tab;
+
for (h = 0; c = *s; ++s)
h ^= 33 * c;
- return h & NR_SYM_HASH-1;
+ h &= NR_SYM_HASH-1;
+
+ tab = (ns == NS_CPP) ? htabcpp : htab;
+ return &tab[h];
}
static void
unlinkhash(Symbol *sym)
{
- Symbol **tab, **h;
+ Symbol **h;
if ((sym->flags & SDECLARED) == 0)
return;
- tab = (sym->ns == NS_CPP) ? htabcpp : htab;
- h = &tab[hash(sym->name)];
+ h = hash(sym->name, sym->ns);
*h = sym->next;
}
_AT_@ -167,10 +171,9 @@ newsym(int ns, char *name)
static Symbol *
linkhash(Symbol *sym)
{
- Symbol **tab, **h;
+ Symbol **h;
- tab = (sym->ns == NS_CPP) ? htabcpp : htab;
- h = &tab[hash(sym->name)];
+ h = hash(sym->name, sym->ns);
sym->hash = *h;
*h = sym;
_AT_@ -207,13 +210,12 @@ newlabel(void)
Symbol *
lookup(int ns, char *name, int alloc)
{
- Symbol *sym, **tab;
+ Symbol *sym;
int sns;
char *t, c;
c = *name;
- tab = (ns == NS_CPP) ? htabcpp : htab;
- for (sym = tab[hash(name)]; sym; sym = sym->hash) {
+ for (sym = *hash(name, ns); sym; sym = sym->hash) {
t = sym->name;
if (*t != c || strcmp(t, name))
continue;
Received on Thu Dec 22 2016 - 16:08:43 CET
This archive was generated by hypermail 2.3.0
: Thu Dec 22 2016 - 16:12:20 CET