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.
This commit is contained in:
Roberto Ierusalimschy
2024-11-13 13:37:24 -03:00
parent 0de8191152
commit 2491b87c10
3 changed files with 81 additions and 29 deletions

View File

@@ -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, "<undef>");
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;
}