aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-13 13:37:24 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-13 13:37:24 -0300
commit2491b87c10db530eac2f3d81cd39f95875d16cd5 (patch)
tree56c066e5e2ccc3eb7b10bea1ba6c60d2b834a8f9 /ltests.c
parent0de81911525bc62bc2a8fc52a368102afed7022b (diff)
downloadlua-2491b87c10db530eac2f3d81cd39f95875d16cd5.tar.gz
lua-2491b87c10db530eac2f3d81cd39f95875d16cd5.tar.bz2
lua-2491b87c10db530eac2f3d81cd39f95875d16cd5.zip
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.
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c11
1 files changed, 7 insertions, 4 deletions
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) {
1043 } 1043 }
1044 else if (cast_uint(i) < asize) { 1044 else if (cast_uint(i) < asize) {
1045 lua_pushinteger(L, i); 1045 lua_pushinteger(L, i);
1046 arr2obj(t, cast_uint(i), s2v(L->top.p)); 1046 if (!tagisempty(*getArrTag(t, i)))
1047 arr2obj(t, cast_uint(i), s2v(L->top.p));
1048 else
1049 setnilvalue(s2v(L->top.p));
1047 api_incr_top(L); 1050 api_incr_top(L);
1048 lua_pushnil(L); 1051 lua_pushnil(L);
1049 } 1052 }
@@ -1057,11 +1060,11 @@ static int table_query (lua_State *L) {
1057 } 1060 }
1058 else 1061 else
1059 lua_pushliteral(L, "<undef>"); 1062 lua_pushliteral(L, "<undef>");
1060 pushobject(L, gval(gnode(t, i))); 1063 if (!isempty(gval(gnode(t, i))))
1061 if (gnext(&t->node[i]) != 0) 1064 pushobject(L, gval(gnode(t, i)));
1062 lua_pushinteger(L, gnext(&t->node[i]));
1063 else 1065 else
1064 lua_pushnil(L); 1066 lua_pushnil(L);
1067 lua_pushinteger(L, gnext(&t->node[i]));
1065 } 1068 }
1066 return 3; 1069 return 3;
1067} 1070}