mirror of
https://github.com/lua/lua
synced 2026-09-27 00:28:25 +03:00
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:
parent
9329eeac3b
commit
002beeebe7
7 changed files with 146 additions and 249 deletions
16
lobject.h
16
lobject.h
|
|
@ -763,24 +763,12 @@ typedef union Node {
|
|||
checkliveness(L,io_); }
|
||||
|
||||
|
||||
/*
|
||||
** About 'alimit': if 'isrealasize(t)' is true, then 'alimit' is the
|
||||
** real size of 'array'. Otherwise, the real size of 'array' is the
|
||||
** smallest power of two not smaller than 'alimit' (or zero iff 'alimit'
|
||||
** is zero); 'alimit' is then used as a hint for #t.
|
||||
*/
|
||||
|
||||
#define BITRAS (1 << 7)
|
||||
#define isrealasize(t) (!((t)->flags & BITRAS))
|
||||
#define setrealasize(t) ((t)->flags &= cast_byte(~BITRAS))
|
||||
#define setnorealasize(t) ((t)->flags |= BITRAS)
|
||||
|
||||
|
||||
typedef struct Table {
|
||||
CommonHeader;
|
||||
lu_byte flags; /* 1<<p means tagmethod(p) is not present */
|
||||
lu_byte lsizenode; /* log2 of size of 'node' array */
|
||||
unsigned int alimit; /* "limit" of 'array' array */
|
||||
lu_byte lsizenode; /* log2 of number of slots of 'node' array */
|
||||
unsigned int asize; /* number of slots in 'array' array */
|
||||
Value *array; /* array part */
|
||||
Node *node;
|
||||
struct Table *metatable;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue