From 002beeebe79065e03dd9f531bee367e8459e3f64 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 29 Nov 2024 17:26:20 -0300 Subject: New way to keep hints for table length Instead of using 'alimit' for keeping the size of the array and at the same time being a hint for '#t', a table now keeps these two values separate. The Table structure has a field 'asize' with the size of the array, while the length hint is kept in the array itself. That way, tables with no array part waste no space with that field. Moreover, the space for the hint may have zero cost for small arrays, if the array of tags plus the hint still fits in a single word. --- ltests.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'ltests.c') diff --git a/ltests.c b/ltests.c index 3edf805e..44ed7bcc 100644 --- a/ltests.c +++ b/ltests.c @@ -359,7 +359,7 @@ static void checkvalref (global_State *g, GCObject *f, const TValue *t) { static void checktable (global_State *g, Table *h) { unsigned int i; - unsigned int asize = luaH_realasize(h); + unsigned int asize = h->asize; Node *n, *limit = gnode(h, sizenode(h)); GCObject *hgc = obj2gco(h); checkobjrefN(g, hgc, h->metatable); @@ -1034,11 +1034,11 @@ static int table_query (lua_State *L) { unsigned int asize; luaL_checktype(L, 1, LUA_TTABLE); t = hvalue(obj_at(L, 1)); - asize = luaH_realasize(t); + asize = t->asize; if (i == -1) { lua_pushinteger(L, cast(lua_Integer, asize)); lua_pushinteger(L, cast(lua_Integer, allocsizenode(t))); - lua_pushinteger(L, cast(lua_Integer, t->alimit)); + lua_pushinteger(L, cast(lua_Integer, asize > 0 ? *lenhint(t) : 0)); return 3; } else if (cast_uint(i) < asize) { -- cgit v1.2.3-55-g6feb