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 /lobject.h | |
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 'lobject.h')
-rw-r--r-- | lobject.h | 16 |
1 files changed, 2 insertions, 14 deletions
@@ -763,24 +763,12 @@ typedef union Node { | |||
763 | checkliveness(L,io_); } | 763 | checkliveness(L,io_); } |
764 | 764 | ||
765 | 765 | ||
766 | /* | ||
767 | ** About 'alimit': if 'isrealasize(t)' is true, then 'alimit' is the | ||
768 | ** real size of 'array'. Otherwise, the real size of 'array' is the | ||
769 | ** smallest power of two not smaller than 'alimit' (or zero iff 'alimit' | ||
770 | ** is zero); 'alimit' is then used as a hint for #t. | ||
771 | */ | ||
772 | |||
773 | #define BITRAS (1 << 7) | ||
774 | #define isrealasize(t) (!((t)->flags & BITRAS)) | ||
775 | #define setrealasize(t) ((t)->flags &= cast_byte(~BITRAS)) | ||
776 | #define setnorealasize(t) ((t)->flags |= BITRAS) | ||
777 | |||
778 | 766 | ||
779 | typedef struct Table { | 767 | typedef struct Table { |
780 | CommonHeader; | 768 | CommonHeader; |
781 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ | 769 | lu_byte flags; /* 1<<p means tagmethod(p) is not present */ |
782 | lu_byte lsizenode; /* log2 of size of 'node' array */ | 770 | lu_byte lsizenode; /* log2 of number of slots of 'node' array */ |
783 | unsigned int alimit; /* "limit" of 'array' array */ | 771 | unsigned int asize; /* number of slots in 'array' array */ |
784 | Value *array; /* array part */ | 772 | Value *array; /* array part */ |
785 | Node *node; | 773 | Node *node; |
786 | struct Table *metatable; | 774 | struct Table *metatable; |