diff options
| author | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-01-12 15:50:51 -0300 |
|---|---|---|
| committer | Roberto Ierusalimschy <roberto@inf.puc-rio.br> | 2024-01-12 15:50:51 -0300 |
| commit | d862da6d04111ce7e5b225040fbe7e526761f478 (patch) | |
| tree | 5fec8b142e05a5e5c97d61161ad7053fb86a3cdb /ltable.h | |
| parent | 7827c40c49d841daca2a40463b8a60f9a113f77e (diff) | |
| download | lua-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 'ltable.h')
| -rw-r--r-- | ltable.h | 19 |
1 files changed, 19 insertions, 0 deletions
| @@ -45,6 +45,25 @@ | |||
| 45 | #define nodefromval(v) cast(Node *, (v)) | 45 | #define nodefromval(v) cast(Node *, (v)) |
| 46 | 46 | ||
| 47 | 47 | ||
| 48 | |||
| 49 | #define luaH_fastgeti(t,k,res,hres) \ | ||
| 50 | { Table *h = t; lua_Unsigned u = l_castS2U(k); \ | ||
| 51 | if ((u - 1u < h->alimit)) { \ | ||
| 52 | int tag = *getArrTag(h,(u)-1u); \ | ||
| 53 | if (tagisempty(tag)) hres = HNOTFOUND; \ | ||
| 54 | else { farr2val(h, u, tag, res); hres = HOK; }} \ | ||
| 55 | else { hres = luaH_getint(h, u, res); }} | ||
| 56 | |||
| 57 | |||
| 58 | #define luaH_fastseti(t,k,val,hres) \ | ||
| 59 | { Table *h = t; lua_Unsigned u = l_castS2U(k); \ | ||
| 60 | if ((u - 1u < h->alimit)) { \ | ||
| 61 | lu_byte *tag = getArrTag(h,(u)-1u); \ | ||
| 62 | if (tagisempty(*tag)) hres = ~cast_int(u); \ | ||
| 63 | else { fval2arr(h, u, tag, val); hres = HOK; }} \ | ||
| 64 | else { hres = luaH_psetint(h, u, val); }} | ||
| 65 | |||
| 66 | |||
| 48 | /* results from get/pset */ | 67 | /* results from get/pset */ |
| 49 | #define HOK 0 | 68 | #define HOK 0 |
| 50 | #define HNOTFOUND 1 | 69 | #define HNOTFOUND 1 |
