diff options
Diffstat (limited to 'src/lj_tab.h')
-rw-r--r-- | src/lj_tab.h | 34 |
1 files changed, 30 insertions, 4 deletions
diff --git a/src/lj_tab.h b/src/lj_tab.h index 4a106873..2a3f76bf 100644 --- a/src/lj_tab.h +++ b/src/lj_tab.h | |||
@@ -31,30 +31,52 @@ static LJ_AINLINE uint32_t hashrot(uint32_t lo, uint32_t hi) | |||
31 | return hi; | 31 | return hi; |
32 | } | 32 | } |
33 | 33 | ||
34 | /* Hash values are masked with the table hash mask and used as an index. */ | ||
35 | static LJ_AINLINE Node *hashmask(const GCtab *t, uint32_t hash) | ||
36 | { | ||
37 | Node *n = noderef(t->node); | ||
38 | return &n[hash & t->hmask]; | ||
39 | } | ||
40 | |||
41 | /* String IDs are generated when a string is interned. */ | ||
42 | #define hashstr(t, s) hashmask(t, (s)->sid) | ||
43 | |||
44 | #define hashlohi(t, lo, hi) hashmask((t), hashrot((lo), (hi))) | ||
45 | #define hashnum(t, o) hashlohi((t), (o)->u32.lo, ((o)->u32.hi << 1)) | ||
46 | #if LJ_GC64 | ||
47 | #define hashgcref(t, r) \ | ||
48 | hashlohi((t), (uint32_t)gcrefu(r), (uint32_t)(gcrefu(r) >> 32)) | ||
49 | #else | ||
50 | #define hashgcref(t, r) hashlohi((t), gcrefu(r), gcrefu(r) + HASH_BIAS) | ||
51 | #endif | ||
52 | |||
34 | #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) | 53 | #define hsize2hbits(s) ((s) ? ((s)==1 ? 1 : 1+lj_fls((uint32_t)((s)-1))) : 0) |
35 | 54 | ||
36 | LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits); | 55 | LJ_FUNCA GCtab *lj_tab_new(lua_State *L, uint32_t asize, uint32_t hbits); |
56 | LJ_FUNC GCtab *lj_tab_new_ah(lua_State *L, int32_t a, int32_t h); | ||
37 | #if LJ_HASJIT | 57 | #if LJ_HASJIT |
38 | LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize); | 58 | LJ_FUNC GCtab * LJ_FASTCALL lj_tab_new1(lua_State *L, uint32_t ahsize); |
39 | #endif | 59 | #endif |
40 | LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt); | 60 | LJ_FUNCA GCtab * LJ_FASTCALL lj_tab_dup(lua_State *L, const GCtab *kt); |
61 | LJ_FUNC void LJ_FASTCALL lj_tab_clear(GCtab *t); | ||
41 | LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t); | 62 | LJ_FUNC void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t); |
42 | #if LJ_HASFFI | 63 | #if LJ_HASFFI |
43 | LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t); | 64 | LJ_FUNC void lj_tab_rehash(lua_State *L, GCtab *t); |
44 | #endif | 65 | #endif |
66 | LJ_FUNC void lj_tab_resize(lua_State *L, GCtab *t, uint32_t asize, uint32_t hbits); | ||
45 | LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize); | 67 | LJ_FUNCA void lj_tab_reasize(lua_State *L, GCtab *t, uint32_t nasize); |
46 | 68 | ||
47 | /* Caveat: all getters except lj_tab_get() can return NULL! */ | 69 | /* Caveat: all getters except lj_tab_get() can return NULL! */ |
48 | 70 | ||
49 | LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key); | 71 | LJ_FUNCA cTValue * LJ_FASTCALL lj_tab_getinth(GCtab *t, int32_t key); |
50 | LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, GCstr *key); | 72 | LJ_FUNC cTValue *lj_tab_getstr(GCtab *t, const GCstr *key); |
51 | LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key); | 73 | LJ_FUNCA cTValue *lj_tab_get(lua_State *L, GCtab *t, cTValue *key); |
52 | 74 | ||
53 | /* Caveat: all setters require a write barrier for the stored value. */ | 75 | /* Caveat: all setters require a write barrier for the stored value. */ |
54 | 76 | ||
55 | LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key); | 77 | LJ_FUNCA TValue *lj_tab_newkey(lua_State *L, GCtab *t, cTValue *key); |
56 | LJ_FUNC TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key); | 78 | LJ_FUNCA TValue *lj_tab_setinth(lua_State *L, GCtab *t, int32_t key); |
57 | LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, GCstr *key); | 79 | LJ_FUNC TValue *lj_tab_setstr(lua_State *L, GCtab *t, const GCstr *key); |
58 | LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); | 80 | LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); |
59 | 81 | ||
60 | #define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize) | 82 | #define inarray(t, key) ((MSize)(key) < (MSize)(t)->asize) |
@@ -64,7 +86,11 @@ LJ_FUNC TValue *lj_tab_set(lua_State *L, GCtab *t, cTValue *key); | |||
64 | #define lj_tab_setint(L, t, key) \ | 86 | #define lj_tab_setint(L, t, key) \ |
65 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key))) | 87 | (inarray((t), (key)) ? arrayslot((t), (key)) : lj_tab_setinth(L, (t), (key))) |
66 | 88 | ||
67 | LJ_FUNCA int lj_tab_next(lua_State *L, GCtab *t, TValue *key); | 89 | LJ_FUNC uint32_t LJ_FASTCALL lj_tab_keyindex(GCtab *t, cTValue *key); |
90 | LJ_FUNCA int lj_tab_next(GCtab *t, cTValue *key, TValue *o); | ||
68 | LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t); | 91 | LJ_FUNCA MSize LJ_FASTCALL lj_tab_len(GCtab *t); |
92 | #if LJ_HASJIT | ||
93 | LJ_FUNC MSize LJ_FASTCALL lj_tab_len_hint(GCtab *t, size_t hint); | ||
94 | #endif | ||
69 | 95 | ||
70 | #endif | 96 | #endif |