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.c32
1 files changed, 10 insertions, 22 deletions
diff --git a/src/lj_tab.c b/src/lj_tab.c
index be26bdda..d77aa05a 100644
--- a/src/lj_tab.c
+++ b/src/lj_tab.c
@@ -98,24 +98,18 @@ static LJ_AINLINE void clearapart(GCtab *t)
98static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits) 98static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
99{ 99{
100 GCtab *t; 100 GCtab *t;
101 global_State *g;
102 /* First try to colocate the array part. */ 101 /* First try to colocate the array part. */
103 if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) { 102 if (LJ_MAX_COLOSIZE && asize > 0 && asize <= LJ_MAX_COLOSIZE) {
104 /* This is ugly. (sizeof(GCtab)&7) != 0. So prepend the colocated array. */ 103 lua_assert((sizeof(GCtab) & 7) == 0);
105 TValue *array = lj_mem_newt(L, sizetabcolo(asize), TValue); 104 t = (GCtab *)lj_mem_newgco(L, sizetabcolo(asize));
106 t = cast(GCtab *, array + asize);
107 g = G(L);
108 setgcrefr(t->nextgc, g->gc.root);
109 setgcref(g->gc.root, obj2gco(t));
110 newwhite(g, t);
111 t->gct = ~LJ_TTAB; 105 t->gct = ~LJ_TTAB;
112 t->nomm = cast_byte(~0); 106 t->nomm = cast_byte(~0);
113 t->colo = (int8_t)asize; 107 t->colo = (int8_t)asize;
114 setmref(t->array, array); 108 setmref(t->array, (TValue *)((char *)t + sizeof(GCtab)));
115 setgcrefnull(t->metatable); 109 setgcrefnull(t->metatable);
116 t->asize = asize; 110 t->asize = asize;
117 t->hmask = 0; 111 t->hmask = 0;
118 setmref(t->node, &g->nilnode); 112 setmref(t->node, &G(L)->nilnode);
119 } else { /* Otherwise separately allocate the array part. */ 113 } else { /* Otherwise separately allocate the array part. */
120 t = lj_mem_newobj(L, GCtab); 114 t = lj_mem_newobj(L, GCtab);
121 t->gct = ~LJ_TTAB; 115 t->gct = ~LJ_TTAB;
@@ -125,8 +119,7 @@ static GCtab *newtab(lua_State *L, uint32_t asize, uint32_t hbits)
125 setgcrefnull(t->metatable); 119 setgcrefnull(t->metatable);
126 t->asize = 0; /* In case the array allocation fails. */ 120 t->asize = 0; /* In case the array allocation fails. */
127 t->hmask = 0; 121 t->hmask = 0;
128 g = G(L); 122 setmref(t->node, &G(L)->nilnode);
129 setmref(t->node, &g->nilnode);
130 if (asize > 0) { 123 if (asize > 0) {
131 if (asize > LJ_MAX_ASIZE) 124 if (asize > LJ_MAX_ASIZE)
132 lj_err_msg(L, LJ_ERR_TABOV); 125 lj_err_msg(L, LJ_ERR_TABOV);
@@ -212,17 +205,12 @@ void LJ_FASTCALL lj_tab_free(global_State *g, GCtab *t)
212{ 205{
213 if (t->hmask > 0) 206 if (t->hmask > 0)
214 lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node); 207 lj_mem_freevec(g, noderef(t->node), t->hmask+1, Node);
215 if (LJ_MAX_COLOSIZE && t->colo) { 208 if (t->asize > 0 && LJ_MAX_COLOSIZE && t->colo <= 0)
216 ptrdiff_t n; 209 lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
217 if (t->colo < 0 && t->asize > 0) /* Array part was separated. */ 210 if (LJ_MAX_COLOSIZE && t->colo)
218 lj_mem_freevec(g, tvref(t->array), t->asize, TValue); 211 lj_mem_free(g, t, sizetabcolo((uint32_t)t->colo & 0x7f));
219 n = t->colo & 0x7f; 212 else
220 lj_mem_free(g, (TValue *)t - n, sizetabcolo((uint32_t)n));
221 } else {
222 if (t->asize > 0)
223 lj_mem_freevec(g, tvref(t->array), t->asize, TValue);
224 lj_mem_freet(g, t); 213 lj_mem_freet(g, t);
225 }
226} 214}
227 215
228/* -- Table resizing ------------------------------------------------------ */ 216/* -- Table resizing ------------------------------------------------------ */