diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 17:56:25 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2023-05-15 17:56:25 -0300 |
commit | 351ccd733298e08c41937c1baf22a68e62bfeca9 (patch) | |
tree | be290db6b41e949c74d6699c7a01963c7cec9b21 /ltable.h | |
parent | 6443185167c77adcc8552a3fee7edab7895db1a9 (diff) | |
download | lua-351ccd733298e08c41937c1baf22a68e62bfeca9.tar.gz lua-351ccd733298e08c41937c1baf22a68e62bfeca9.tar.bz2 lua-351ccd733298e08c41937c1baf22a68e62bfeca9.zip |
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.)
Diffstat (limited to 'ltable.h')
-rw-r--r-- | ltable.h | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -35,6 +35,27 @@ | |||
35 | #define nodefromval(v) cast(Node *, (v)) | 35 | #define nodefromval(v) cast(Node *, (v)) |
36 | 36 | ||
37 | 37 | ||
38 | /* results from get/set */ | ||
39 | #define HOK 0 | ||
40 | #define HNOTFOUND 1 | ||
41 | #define HNOTATABLE 2 | ||
42 | |||
43 | |||
44 | /* fast access to components of array values */ | ||
45 | #define getArrTag(t,k) (&(t)->array[k - 1].tt_) | ||
46 | #define getArrVal(t,k) (&(t)->array[k - 1].value_) | ||
47 | |||
48 | #define tagisempty(tag) (novariant(tag) == LUA_TNIL) | ||
49 | |||
50 | #define arr2val(h,k,tag,res) \ | ||
51 | ((res)->tt_ = tag, (res)->value_ = *getArrVal(h,k)) | ||
52 | |||
53 | |||
54 | LUAI_FUNC int luaH_getshortstr1 (Table *t, TString *key, TValue *res); | ||
55 | LUAI_FUNC int luaH_getstr1 (Table *t, TString *key, TValue *res); | ||
56 | LUAI_FUNC int luaH_get1 (Table *t, const TValue *key, TValue *res); | ||
57 | LUAI_FUNC int luaH_getint1 (Table *t, lua_Integer key, TValue *res); | ||
58 | |||
38 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); | 59 | LUAI_FUNC const TValue *luaH_getint (Table *t, lua_Integer key); |
39 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, | 60 | LUAI_FUNC void luaH_setint (lua_State *L, Table *t, lua_Integer key, |
40 | TValue *value); | 61 | TValue *value); |