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 /lvm.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 'lvm.h')
-rw-r--r-- | lvm.h | 17 |
1 files changed, 15 insertions, 2 deletions
@@ -89,6 +89,10 @@ typedef enum { | |||
89 | !isempty(slot))) /* result not empty? */ | 89 | !isempty(slot))) /* result not empty? */ |
90 | 90 | ||
91 | 91 | ||
92 | #define luaV_fastget1(t,k,res,f, aux) \ | ||
93 | (aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res))) | ||
94 | |||
95 | |||
92 | /* | 96 | /* |
93 | ** Special case of 'luaV_fastget' for integers, inlining the fast case | 97 | ** Special case of 'luaV_fastget' for integers, inlining the fast case |
94 | ** of 'luaH_getint'. | 98 | ** of 'luaH_getint'. |
@@ -100,6 +104,15 @@ typedef enum { | |||
100 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ | 104 | ? &hvalue(t)->array[k - 1] : luaH_getint(hvalue(t), k), \ |
101 | !isempty(slot))) /* result not empty? */ | 105 | !isempty(slot))) /* result not empty? */ |
102 | 106 | ||
107 | #define luaV_fastgeti1(t,k,val,aux) \ | ||
108 | if (!ttistable(t)) aux = HNOTATABLE; \ | ||
109 | else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \ | ||
110 | if ((u - 1u < h->alimit)) { \ | ||
111 | int tag = *getArrTag(h,u); \ | ||
112 | if (tagisempty(tag)) aux = HNOTFOUND; \ | ||
113 | else { arr2val(h, u, tag, val); aux = HOK; }} \ | ||
114 | else { aux = luaH_getint1(h, u, val); }} | ||
115 | |||
103 | 116 | ||
104 | /* | 117 | /* |
105 | ** Finish a fast set operation (when fast get succeeds). In that case, | 118 | ** Finish a fast set operation (when fast get succeeds). In that case, |
@@ -125,8 +138,8 @@ LUAI_FUNC int luaV_tointeger (const TValue *obj, lua_Integer *p, F2Imod mode); | |||
125 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, | 138 | LUAI_FUNC int luaV_tointegerns (const TValue *obj, lua_Integer *p, |
126 | F2Imod mode); | 139 | F2Imod mode); |
127 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); | 140 | LUAI_FUNC int luaV_flttointeger (lua_Number n, lua_Integer *p, F2Imod mode); |
128 | LUAI_FUNC void luaV_finishget (lua_State *L, const TValue *t, TValue *key, | 141 | LUAI_FUNC void luaV_finishget1 (lua_State *L, const TValue *t, TValue *key, |
129 | StkId val, const TValue *slot); | 142 | StkId val, int aux); |
130 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, | 143 | LUAI_FUNC void luaV_finishset (lua_State *L, const TValue *t, TValue *key, |
131 | TValue *val, const TValue *slot); | 144 | TValue *val, const TValue *slot); |
132 | LUAI_FUNC void luaV_finishOp (lua_State *L); | 145 | LUAI_FUNC void luaV_finishOp (lua_State *L); |