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.
This commit is contained in:
Roberto Ierusalimschy
2024-11-29 17:26:20 -03:00
parent 9329eeac3b
commit 002beeebe7
7 changed files with 146 additions and 249 deletions

2
lvm.c
View File

@@ -1865,7 +1865,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
pc++;
}
/* when 'n' is known, table should have proper size */
if (last > luaH_realasize(h)) { /* needs more space? */
if (last > h->asize) { /* needs more space? */
/* fixed-size sets should have space preallocated */
lua_assert(GETARG_vB(i) == 0);
luaH_resizearray(L, h, last); /* preallocate it at once */