OP_NEWTABLE keeps exact size of arrays

OP_NEWTABLE is followed by an OP_EXTRAARG, so that it can keep
the exact size of the array part of the table to be created.
(Functions 'luaO_int2fb'/'luaO_fb2int' were removed.)
This commit is contained in:
Roberto Ierusalimschy
2019-07-12 16:13:50 -03:00
parent f6aab3ec1f
commit 1fb4d53925
10 changed files with 67 additions and 88 deletions

6
lvm.c
View File

@@ -1250,11 +1250,15 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
int b = GETARG_B(i);
int c = GETARG_C(i);
Table *t;
c = (c == 0) ? 0 : 1 << (c - 1); /* size is 2^c */
if (b >= LIMTABSZ)
b += LFIELDS_PER_FLUSH * GETARG_Ax(*pc) - LIMTABSZ;
pc++; /* skip extra argument */
L->top = ci->top; /* correct top in case of GC */
t = luaH_new(L); /* memory allocation */
sethvalue2s(L, ra, t);
if (b != 0 || c != 0)
luaH_resize(L, t, luaO_fb2int(b), luaO_fb2int(c)); /* idem */
luaH_resize(L, t, b, c); /* idem */
checkGC(L, ra + 1);
vmbreak;
}