diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-29 17:26:20 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-11-29 17:26:20 -0300 |
commit | 002beeebe79065e03dd9f531bee367e8459e3f64 (patch) | |
tree | 5b066d30e08950c923c253ce85f702b39fbe9c31 /lgc.c | |
parent | 9329eeac3b7035c223d7a8b63dbde1f6db371bf5 (diff) | |
download | lua-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 'lgc.c')
-rw-r--r-- | lgc.c | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -486,7 +486,7 @@ static void traverseweakvalue (global_State *g, Table *h) { | |||
486 | Node *n, *limit = gnodelast(h); | 486 | Node *n, *limit = gnodelast(h); |
487 | /* if there is array part, assume it may have white values (it is not | 487 | /* if there is array part, assume it may have white values (it is not |
488 | worth traversing it now just to check) */ | 488 | worth traversing it now just to check) */ |
489 | int hasclears = (h->alimit > 0); | 489 | int hasclears = (h->asize > 0); |
490 | for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ | 490 | for (n = gnode(h, 0); n < limit; n++) { /* traverse hash part */ |
491 | if (isempty(gval(n))) /* entry is empty? */ | 491 | if (isempty(gval(n))) /* entry is empty? */ |
492 | clearkey(n); /* clear its key */ | 492 | clearkey(n); /* clear its key */ |
@@ -508,7 +508,7 @@ static void traverseweakvalue (global_State *g, Table *h) { | |||
508 | ** Traverse the array part of a table. | 508 | ** Traverse the array part of a table. |
509 | */ | 509 | */ |
510 | static int traversearray (global_State *g, Table *h) { | 510 | static int traversearray (global_State *g, Table *h) { |
511 | unsigned asize = luaH_realasize(h); | 511 | unsigned asize = h->asize; |
512 | int marked = 0; /* true if some object is marked in this traversal */ | 512 | int marked = 0; /* true if some object is marked in this traversal */ |
513 | unsigned i; | 513 | unsigned i; |
514 | for (i = 0; i < asize; i++) { | 514 | for (i = 0; i < asize; i++) { |
@@ -604,7 +604,7 @@ static l_mem traversetable (global_State *g, Table *h) { | |||
604 | } | 604 | } |
605 | else /* not weak */ | 605 | else /* not weak */ |
606 | traversestrongtable(g, h); | 606 | traversestrongtable(g, h); |
607 | return 1 + 2*sizenode(h) + h->alimit; | 607 | return 1 + 2*sizenode(h) + h->asize; |
608 | } | 608 | } |
609 | 609 | ||
610 | 610 | ||
@@ -790,7 +790,7 @@ static void clearbyvalues (global_State *g, GCObject *l, GCObject *f) { | |||
790 | Table *h = gco2t(l); | 790 | Table *h = gco2t(l); |
791 | Node *n, *limit = gnodelast(h); | 791 | Node *n, *limit = gnodelast(h); |
792 | unsigned int i; | 792 | unsigned int i; |
793 | unsigned int asize = luaH_realasize(h); | 793 | unsigned int asize = h->asize; |
794 | for (i = 0; i < asize; i++) { | 794 | for (i = 0; i < asize; i++) { |
795 | GCObject *o = gcvalarr(h, i); | 795 | GCObject *o = gcvalarr(h, i); |
796 | if (iscleared(g, o)) /* value was collected? */ | 796 | if (iscleared(g, o)) /* value was collected? */ |