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'. --- ltable.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'ltable.h') diff --git a/ltable.h b/ltable.h index 5581efb1..8b0340b5 100644 --- a/ltable.h +++ b/ltable.h @@ -45,6 +45,25 @@ #define nodefromval(v) cast(Node *, (v)) + +#define luaH_fastgeti(t,k,res,hres) \ + { Table *h = t; lua_Unsigned u = l_castS2U(k); \ + if ((u - 1u < h->alimit)) { \ + int tag = *getArrTag(h,(u)-1u); \ + if (tagisempty(tag)) hres = HNOTFOUND; \ + else { farr2val(h, u, tag, res); hres = HOK; }} \ + else { hres = luaH_getint(h, u, res); }} + + +#define luaH_fastseti(t,k,val,hres) \ + { Table *h = t; lua_Unsigned u = l_castS2U(k); \ + if ((u - 1u < h->alimit)) { \ + lu_byte *tag = getArrTag(h,(u)-1u); \ + if (tagisempty(*tag)) hres = ~cast_int(u); \ + else { fval2arr(h, u, tag, val); hres = HOK; }} \ + else { hres = luaH_psetint(h, u, val); }} + + /* results from get/pset */ #define HOK 0 #define HNOTFOUND 1 -- cgit v1.2.3-55-g6feb