summaryrefslogtreecommitdiff
path: root/src/lj_tab.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lj_tab.c')
-rw-r--r--src/lj_tab.c21
1 files changed, 9 insertions, 12 deletions
diff --git a/src/lj_tab.c b/src/lj_tab.c
index 006a87ff..d6175bbd 100644
--- a/src/lj_tab.c
+++ b/src/lj_tab.c
@@ -17,22 +17,19 @@
17/* -- Object hashing ------------------------------------------------------ */ 17/* -- Object hashing ------------------------------------------------------ */
18 18
19/* Hash values are masked with the table hash mask and used as an index. */ 19/* Hash values are masked with the table hash mask and used as an index. */
20#define hashmask(t, x) (&noderef(t->node)[(x) & t->hmask]) 20static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash)
21{
22 Node *n = noderef(t->node);
23 return &n[hash & t->hmask];
24}
21 25
22/* String hashes are precomputed when they are interned. */ 26/* String hashes are precomputed when they are interned. */
23#define hashstr(t, s) hashmask(t, (s)->hash) 27#define hashstr(t, s) hashmask(t, (s)->hash)
24 28
25#define hashnum(t, o) hashrot(t, (o)->u32.lo, ((o)->u32.hi << 1)) 29#define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi)))
26#define hashgcref(t, r) hashrot(t, gcrefu(r), gcrefu(r)-0x04c11db7) 30#define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1))
27 31#define hashptr(t, p) hashlohi((t), u32ptr(p), u32ptr(p) + HASH_BIAS)
28/* Scramble the bits of numbers and pointers. */ 32#define hashgcref(t, r) hashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS)
29static LJ_AINLINE Node *hashrot(const GCtab *t, uint32_t lo, uint32_t hi)
30{
31 lo ^= hi; hi = lj_rol(hi, 14);
32 lo -= hi; hi = lj_rol(hi, 5);
33 hi ^= lo; hi -= lj_rol(lo, 27);
34 return hashmask(t, hi);
35}
36 33
37/* Hash an arbitrary key and return its anchor position in the hash table. */ 34/* Hash an arbitrary key and return its anchor position in the hash table. */
38static Node *hashkey(const GCtab *t, cTValue *key) 35static Node *hashkey(const GCtab *t, cTValue *key)