From d862da6d04111ce7e5b225040fbe7e526761f478 Mon Sep 17 00:00:00 2001 From: Roberto Ierusalimschy Date: Fri, 12 Jan 2024 15:50:51 -0300 Subject: 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'. --- lvm.h | 36 +++++++++++++----------------------- 1 file changed, 13 insertions(+), 23 deletions(-) (limited to 'lvm.h') diff --git a/lvm.h b/lvm.h index c74c81f8..54ee5dd7 100644 --- a/lvm.h +++ b/lvm.h @@ -78,35 +78,25 @@ typedef enum { /* ** fast track for 'gettable' */ -#define luaV_fastget(t,k,res,f, aux) \ - (aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res))) +#define luaV_fastget(t,k,res,f, hres) \ + (hres = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, res))) /* ** Special case of 'luaV_fastget' for integers, inlining the fast case ** of 'luaH_getint'. */ -#define luaV_fastgeti(t,k,res,aux) \ - if (!ttistable(t)) aux = HNOTATABLE; \ - else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \ - if ((u - 1u < h->alimit)) { \ - int tag = *getArrTag(h,(u)-1u); \ - if (tagisempty(tag)) aux = HNOTFOUND; \ - else { farr2val(h, u, tag, res); aux = HOK; }} \ - else { aux = luaH_getint(h, u, res); }} - - -#define luaV_fastset(t,k,val,aux,f) \ - (aux = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, val))) - -#define luaV_fastseti(t,k,val,aux) \ - if (!ttistable(t)) aux = HNOTATABLE; \ - else { Table *h = hvalue(t); lua_Unsigned u = l_castS2U(k); \ - if ((u - 1u < h->alimit)) { \ - lu_byte *tag = getArrTag(h,(u)-1u); \ - if (tagisempty(*tag)) aux = ~cast_int(u); \ - else { fval2arr(h, u, tag, val); aux = HOK; }} \ - else { aux = luaH_psetint(h, u, val); }} +#define luaV_fastgeti(t,k,res,hres) \ + if (!ttistable(t)) hres = HNOTATABLE; \ + else { luaH_fastgeti(hvalue(t), k, res, hres); } + + +#define luaV_fastset(t,k,val,hres,f) \ + (hres = (!ttistable(t) ? HNOTATABLE : f(hvalue(t), k, val))) + +#define luaV_fastseti(t,k,val,hres) \ + if (!ttistable(t)) hres = HNOTATABLE; \ + else { luaH_fastseti(hvalue(t), k, val, hres); } /* -- cgit v1.2.3-55-g6feb