diff options
author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-21 11:23:21 -0300 |
---|---|---|
committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-03-21 11:23:21 -0300 |
commit | 0593256707ceddb1bc9cd4b25b822a7fbcfedd66 (patch) | |
tree | 6c6859b94086b71b27409b565ed34c114f03e7f8 /ltable.h | |
parent | ce6f5502c99ce9a367e25b678e375db6f8164d73 (diff) | |
download | lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.tar.gz lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.tar.bz2 lua-0593256707ceddb1bc9cd4b25b822a7fbcfedd66.zip |
'luaH_get' functions return tag of the result
Undoing previous commit. Returning TValue increases code size without
any visible gains. Returning the tag is a little simpler than returning
a special code (HOK/HNOTFOUND) and the tag is useful by itself in
some cases.
Diffstat (limited to 'ltable.h')
-rw-r--r-- | ltable.h | 29 |
1 files changed, 16 insertions, 13 deletions
@@ -46,11 +46,12 @@ | |||
46 | 46 | ||
47 | 47 | ||
48 | 48 | ||
49 | #define luaH_fastgeti(t,k,res,aux) \ | 49 | #define luaH_fastgeti(t,k,res,tag) \ |
50 | { Table *h = t; lua_Unsigned u = l_castS2U(k); \ | 50 | { Table *h = t; lua_Unsigned u = l_castS2U(k); \ |
51 | if ((u - 1u < h->alimit)) arr2objV(h,u,aux); \ | 51 | if ((u - 1u < h->alimit)) { \ |
52 | else aux = luaH_getint(h, u); \ | 52 | tag = *getArrTag(h,(u)-1u); \ |
53 | if (!isemptyV(aux)) setobjV(cast(lua_State*, NULL), res, aux); } | 53 | if (!tagisempty(tag)) { farr2val(h, u, tag, res); }} \ |
54 | else { tag = luaH_getint(h, u, res); }} | ||
54 | 55 | ||
55 | 56 | ||
56 | #define luaH_fastseti(t,k,val,hres) \ | 57 | #define luaH_fastseti(t,k,val,hres) \ |
@@ -69,6 +70,8 @@ | |||
69 | #define HFIRSTNODE 3 | 70 | #define HFIRSTNODE 3 |
70 | 71 | ||
71 | /* | 72 | /* |
73 | ** 'luaH_get*' operations set 'res', unless the value is absent, and | ||
74 | ** return the tag of the result, | ||
72 | ** The 'luaH_pset*' (pre-set) operations set the given value and return | 75 | ** The 'luaH_pset*' (pre-set) operations set the given value and return |
73 | ** HOK, unless the original value is absent. In that case, if the key | 76 | ** HOK, unless the original value is absent. In that case, if the key |
74 | ** is really absent, they return HNOTFOUND. Otherwise, if there is a | 77 | ** is really absent, they return HNOTFOUND. Otherwise, if there is a |
@@ -85,7 +88,8 @@ | |||
85 | /* | 88 | /* |
86 | ** The array part of a table is represented by an array of cells. | 89 | ** The array part of a table is represented by an array of cells. |
87 | ** Each cell is composed of NM tags followed by NM values, so that | 90 | ** Each cell is composed of NM tags followed by NM values, so that |
88 | ** no space is wasted in padding. | 91 | ** no space is wasted in padding. The last cell may be incomplete, |
92 | ** that is, it may have fewer than NM values. | ||
89 | */ | 93 | */ |
90 | #define NM cast_uint(sizeof(Value)) | 94 | #define NM cast_uint(sizeof(Value)) |
91 | 95 | ||
@@ -105,10 +109,8 @@ struct ArrayCell { | |||
105 | /* | 109 | /* |
106 | ** Move TValues to/from arrays, using Lua indices | 110 | ** Move TValues to/from arrays, using Lua indices |
107 | */ | 111 | */ |
108 | #define arr2objV(h,k,val) \ | 112 | #define arr2obj(h,k,val) \ |
109 | ((val).tt_ = *getArrTag(h,(k)-1u), (val).value_ = *getArrVal(h,(k)-1u)) | 113 | ((val)->tt_ = *getArrTag(h,(k)-1u), (val)->value_ = *getArrVal(h,(k)-1u)) |
110 | |||
111 | #define arr2obj(h,k,val) arr2objV(h,k,*(val)) | ||
112 | 114 | ||
113 | #define obj2arr(h,k,val) \ | 115 | #define obj2arr(h,k,val) \ |
114 | (*getArrTag(h,(k)-1u) = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_) | 116 | (*getArrTag(h,(k)-1u) = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_) |
@@ -126,11 +128,12 @@ struct ArrayCell { | |||
126 | (*tag = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_) | 128 | (*tag = (val)->tt_, *getArrVal(h,(k)-1u) = (val)->value_) |
127 | 129 | ||
128 | 130 | ||
129 | LUAI_FUNC TValue luaH_get (Table *t, const TValue *key); | 131 | LUAI_FUNC int luaH_get (Table *t, const TValue *key, TValue *res); |
130 | LUAI_FUNC TValue luaH_getshortstr (Table *t, TString *key); | 132 | LUAI_FUNC int luaH_getshortstr (Table *t, TString *key, TValue *res); |
131 | LUAI_FUNC TValue luaH_getstr (Table *t, TString *key); | 133 | LUAI_FUNC int luaH_getstr (Table *t, TString *key, TValue *res); |
132 | LUAI_FUNC TValue luaH_getint (Table *t, lua_Integer key); | 134 | LUAI_FUNC int luaH_getint (Table *t, lua_Integer key, TValue *res); |
133 | 135 | ||
136 | /* Special get for metamethods */ | ||
134 | LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key); | 137 | LUAI_FUNC const TValue *luaH_Hgetshortstr (Table *t, TString *key); |
135 | 138 | ||
136 | LUAI_FUNC TString *luaH_getstrkey (Table *t, TString *key); | 139 | LUAI_FUNC TString *luaH_getstrkey (Table *t, TString *key); |