lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


> 0. Why Table.flags type is lu_byte(unsigned char)? We have 17
> metamethods. Should it be unsigned short int instead? Then we cache 16
> metamethods.

"Fast access" is only faster when there is no metamethod. In the current
implementation, the metamethods without fast access are those that raise
an error whenever they are absent. So, that change would only optimize
the error handling (and would slow down a very little bit the non-error
behavior).


> On x86 there is no drawback having it unsigned short int instead of
> unsigned char(due to the alignment).

In Lua 5.1, the 'flags' field comes between two lu_byte and one lu_byte:

  typedef struct Table {
  CommonHeader;     /* --> GCObject *next; lu_byte tt; lu_byte marked */
  lu_byte flags;  /* 1<<p means tagmethod(p) is not present */
  lu_byte lsizenode;  /* log2 of size of `node' array */

All four fields fit in a word. Changing it to short would force 'lsizenode'
into another word.

-- Roberto