Towards a new implementation of arrays

The array part of a table wastes too much space, due to padding.
To avoid that, we need to store values in the array as something
different from a TValue. Therefore, the API for table access
should not assume that any value in a table lives in a *TValue.
This commit is the first step to remove that assumption: functions
luaH_get*, instead of returning a *TValue where the value lives,
receive a *TValue where to put the value being accessed.
(We still have to change the luaH_set* functions.)
This commit is contained in:
Roberto Ierusalimschy
2023-05-15 17:56:25 -03:00
parent 6443185167
commit 351ccd7332
5 changed files with 108 additions and 59 deletions

View File

@@ -35,6 +35,27 @@
#define nodefromval(v) cast(Node *, (v))
/* results from get/set */
#define HOK 0
#define HNOTFOUND 1
#define HNOTATABLE 2
/* fast access to components of array values */
#define getArrTag(t,k) (&(t)->array[k - 1].tt_)
#define getArrVal(t,k) (&(t)->array[k - 1].value_)
#define tagisempty(tag) (novariant(tag) == LUA_TNIL)
#define arr2val(h,k,tag,res) \
((res)->tt_ = tag, (res)->value_ = *getArrVal(h,k))
LUAI_FUNC int luaH_getshortstr1 (Table *t, TString *key, TValue *res);
LUAI_FUNC int luaH_getstr1 (Table *t, TString *key, TValue *res);
LUAI_FUNC int luaH_get1 (Table *t, const TValue *key, TValue *res);
LUAI_FUNC int luaH_getint1 (Table *t, lua_Integer key, TValue *res);
LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key);
LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key,
TValue *value);