aboutsummaryrefslogtreecommitdiff
path: root/lvm.h
diff options
context:
space:
mode:
authorRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-12 15:50:51 -0300
committerRoberto Ierusalimschy <roberto@inf.puc-rio.br>2024-01-12 15:50:51 -0300
commitd862da6d04111ce7e5b225040fbe7e526761f478 (patch)
tree5fec8b142e05a5e5c97d61161ad7053fb86a3cdb /lvm.h
parent7827c40c49d841daca2a40463b8a60f9a113f77e (diff)
downloadlua-d862da6d04111ce7e5b225040fbe7e526761f478.tar.gz
lua-d862da6d04111ce7e5b225040fbe7e526761f478.tar.bz2
lua-d862da6d04111ce7e5b225040fbe7e526761f478.zip
Optimizations for 'lua_rawgeti' and 'lua_rawseti'
'lua_rawgeti' now uses "fast track"; 'lua_rawseti' still calls 'luaH_setint', but the latter was recoded to avoid extra overhead when writing to the array part after 'alimit'.
Diffstat (limited to 'lvm.h')
-rw-r--r--lvm.h36
1 files changed, 13 insertions, 23 deletions
diff --git a/lvm.h b/lvm.h
index c74c81f8..54ee5dd7 100644
--- a/lvm.h
+++ b/lvm.h
@@ -78,35 +78,25 @@ typedef enum {
78/* 78/*
79** fast track for 'gettable' 79** fast track for 'gettable'
80*/ 80*/
81#define luaV_fastget(t,k,res,f, aux) \ 81#define luaV_fastget(t,k,res,f, hres) \
82 (aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res))) 82 (hres = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res)))
83 83
84 84
85/* 85/*
86** Special case of 'luaV_fastget' for integers, inlining the fast case 86** Special case of 'luaV_fastget' for integers, inlining the fast case
87** of 'luaH_getint'. 87** of 'luaH_getint'.
88*/ 88*/
89#define luaV_fastgeti(t,k,res,aux) \ 89#define luaV_fastgeti(t,k,res,hres) \
90 if (!ttistable(t)) aux = HNOTATABLE; \ 90 if (!ttistable(t)) hres = HNOTATABLE; \
91 else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \ 91 else { luaH_fastgeti(hvalue(t), k, res, hres); }
92 if ((u - 1u < h->alimit)) { \ 92
93 int tag = *getArrTag(h,(u)-1u); \ 93
94 if (tagisempty(tag)) aux = HNOTFOUND; \ 94#define luaV_fastset(t,k,val,hres,f) \
95 else { farr2val(h, u, tag, res); aux = HOK; }} \ 95 (hres = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, val)))
96 else { aux = luaH_getint(h, u, res); }} 96
97 97#define luaV_fastseti(t,k,val,hres) \
98 98 if (!ttistable(t)) hres = HNOTATABLE; \
99#define luaV_fastset(t,k,val,aux,f) \ 99 else { luaH_fastseti(hvalue(t), k, val, hres); }
100 (aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, val)))
101
102#define luaV_fastseti(t,k,val,aux) \
103 if (!ttistable(t)) aux = HNOTATABLE; \
104 else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \
105 if ((u - 1u < h->alimit)) { \
106 lu_byte *tag = getArrTag(h,(u)-1u); \
107 if (tagisempty(*tag)) aux = ~cast_int(u); \
108 else { fval2arr(h, u, tag, val); aux = HOK; }} \
109 else { aux = luaH_psetint(h, u, val); }}
110 100
111 101
112/* 102/*