aboutsummaryrefslogtreecommitdiff
path: root/ltests.c
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-29 17:26:20 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-11-29 17:26:20 -0300
commit002beeebe79065e03dd9f531bee367e8459e3f64 (patch)
tree5b066d30e08950c923c253ce85f702b39fbe9c31 /ltests.c
parent9329eeac3b7035c223d7a8b63dbde1f6db371bf5 (diff)
downloadlua-002beeebe79065e03dd9f531bee367e8459e3f64.tar.gz
lua-002beeebe79065e03dd9f531bee367e8459e3f64.tar.bz2
lua-002beeebe79065e03dd9f531bee367e8459e3f64.zip
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.
Diffstat (limited to 'ltests.c')
-rw-r--r--ltests.c6
1 files changed, 3 insertions, 3 deletions
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) {
359 359
360static void checktable (global_State *g, Table *h) { 360static void checktable (global_State *g, Table *h) {
361 unsigned int i; 361 unsigned int i;
362 unsigned int asize = luaH_realasize(h); 362 unsigned int asize = h->asize;
363 Node *n, *limit = gnode(h, sizenode(h)); 363 Node *n, *limit = gnode(h, sizenode(h));
364 GCObject *hgc = obj2gco(h); 364 GCObject *hgc = obj2gco(h);
365 checkobjrefN(g, hgc, h->metatable); 365 checkobjrefN(g, hgc, h->metatable);
@@ -1034,11 +1034,11 @@ static int table_query (lua_State *L) {
1034 unsigned int asize; 1034 unsigned int asize;
1035 luaL_checktype(L, 1, LUA_TTABLE); 1035 luaL_checktype(L, 1, LUA_TTABLE);
1036 t = hvalue(obj_at(L, 1)); 1036 t = hvalue(obj_at(L, 1));
1037 asize = luaH_realasize(t); 1037 asize = t->asize;
1038 if (i == -1) { 1038 if (i == -1) {
1039 lua_pushinteger(L, cast(lua_Integer, asize)); 1039 lua_pushinteger(L, cast(lua_Integer, asize));
1040 lua_pushinteger(L, cast(lua_Integer, allocsizenode(t))); 1040 lua_pushinteger(L, cast(lua_Integer, allocsizenode(t)));
1041 lua_pushinteger(L, cast(lua_Integer, t->alimit)); 1041 lua_pushinteger(L, cast(lua_Integer, asize > 0 ? *lenhint(t) : 0));
1042 return 3; 1042 return 3;
1043 } 1043 }
1044 else if (cast_uint(i) < asize) { 1044 else if (cast_uint(i) < asize) {