From 2491b87c10db530eac2f3d81cd39f95875d16cd5 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Wed, 13 Nov 2024 13:37:24 -0300 Subject: New rule for size of array part Array part needs 1/3 of its elements filled, instead of 1/2. Array entries use ~1/3 the memory of hash entries, so this new rule still ensures that array parts do not use more memory than keeping the values in the hash, while allowing more uses of the array part, which is more efficient than the hash. --- ltests.c | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index 2dafbee5..8191f14a 100644 --- a/ltests.c +++ b/ltests.c @@ -1043,7 +1043,10 @@ static int table_query (lua_State *L) { } else if (cast_uint(i) < asize) { lua_pushinteger(L, i); - arr2obj(t, cast_uint(i), s2v(L->top.p)); + if (!tagisempty(*getArrTag(t, i))) + arr2obj(t, cast_uint(i), s2v(L->top.p)); + else + setnilvalue(s2v(L->top.p)); api_incr_top(L); lua_pushnil(L); } @@ -1057,11 +1060,11 @@ static int table_query (lua_State *L) { } else lua_pushliteral(L, ""); - pushobject(L, gval(gnode(t, i))); - if (gnext(&t->node[i]) != 0) - lua_pushinteger(L, gnext(&t->node[i])); + if (!isempty(gval(gnode(t, i)))) + pushobject(L, gval(gnode(t, i))); else lua_pushnil(L); + lua_pushinteger(L, gnext(&t->node[i])); } return 3; } -- cgit v1.2.3-55-g6feb