From a6b29bccb74c43f5af60b9855ef7fae3fc613a88 Mon Sep 17 00:00:00 2001 From: Christoffer Lerno Date: Mon, 10 Jan 2022 22:05:56 +0100 Subject: [PATCH] Somewhat smaller SymEntry. Different mixing function in stables. --- src/compiler/symtab.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/symtab.c b/src/compiler/symtab.c index afdd23140..bc21df4d7 100644 --- a/src/compiler/symtab.c +++ b/src/compiler/symtab.c @@ -9,8 +9,8 @@ typedef struct _SymEntry { const char *value; - TokenType type; - uint32_t key_len; + uint16_t key_len; + TokenType type : 16; uint32_t hash; } SymEntry; @@ -284,12 +284,15 @@ void stable_clear(STable *table) static inline SEntry *sentry_find(SEntry *entries, uint32_t capacity, const char *key) { - uint32_t index = (uint32_t)((((uintptr_t)key) >> 2u) & (capacity - 1)); + uintptr_t hash_key = (uintptr_t)key; + uint32_t mask = capacity - 1; + hash_key ^= hash_key >> 16; + uint32_t index = (uint32_t)hash_key & mask; while (1) { SEntry *entry = &entries[index]; if (entry->key == key || !entry->key) return entry; - index = (index + 1) & (capacity - 1); + index = (index + 1) & mask; } }