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. --- lgc.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'lgc.c') diff --git a/lgc.c b/lgc.c index e4130bd5..3cdfd006 100644 --- a/lgc.c +++ b/lgc.c @@ -486,7 +486,7 @@ static void traverseweakvalue (global_State *g, Table *h) { Node *n, *limit = gnodelast(h); /* if there is array part, assume it may have white values (it is not worth traversing it now just to check) */ - int hasclears = (h->alimit > 0); + int hasclears = (h->asize > 0); for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ if (isempty(gval(n))) /* entry is empty? */ clearkey(n); /* clear its key */ @@ -508,7 +508,7 @@ static void traverseweakvalue (global_State *g, Table *h) { ** Traverse the array part of a table. */ static int traversearray (global_State *g, Table *h) { - unsigned asize = luaH_realasize(h); + unsigned asize = h->asize; int marked = 0; /* true if some object is marked in this traversal */ unsigned i; for (i = 0; i < asize; i++) { @@ -604,7 +604,7 @@ static l_mem traversetable (global_State *g, Table *h) { } else /* not weak */ traversestrongtable(g, h); - return 1 + 2*sizenode(h) + h->alimit; + return 1 + 2*sizenode(h) + h->asize; } @@ -790,7 +790,7 @@ static void clearbyvalues (global_State *g, GCObject *l, GCObject *f) { Table *h = gco2t(l); Node *n, *limit = gnodelast(h); unsigned int i; - unsigned int asize = luaH_realasize(h); + unsigned int asize = h->asize; for (i = 0; i < asize; i++) { GCObject *o = gcvalarr(h, i); if (iscleared(g, o)) /* value was collected? */ -- cgit v1.2.3-55-g6feb