From 351ccd733298e08c41937c1baf22a68e62bfeca9 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Mon, 15 May 2023 17:56:25 -0300 Subject: 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.) --- ltable.h | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'ltable.h') diff --git a/ltable.h b/ltable.h index 75dd9e26..c8a8c5e7 100644 --- a/ltable.h +++ b/ltable.h @@ -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); -- cgit v1.2.3-55-g6feb