From 1c75dd0401c47ac21f3459f2425d5fc826cd137b Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:26 +0200 Subject: [PATCH 01/11] Revert "blua: fix copy paste error for "slow path" in auxgetstr/lua_getfield" This reverts commit b652d802f5927f4b5efe253b99c4bb4773fbcfa7. --- src/blua/lapi.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/blua/lapi.c b/src/blua/lapi.c index e494e9fc9..bca24a90f 100644 --- a/src/blua/lapi.c +++ b/src/blua/lapi.c @@ -526,12 +526,13 @@ static void auxgetstr (lua_State *L, TValue *t, const char *k) { api_checkvalidindex(L, t); if (luaV_fastget(L, t, str, slot, luaH_getstr)) { setobj2s(L, L->top, slot); + api_incr_top(L); } else { setsvalue(L, &key, str); - luaV_finishget(L, t, &key, L->top, slot); + luaV_finishget(L, t, L->top, L->top, slot); + api_incr_top(L); } - api_incr_top(L); lua_unlock(L); } From 9f9e6450f2c8ec1597fbaabad4e1ca14412ae517 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:33 +0200 Subject: [PATCH 02/11] Revert "Blua: opcode OP_SELF operate only with string keys, so they can use fast-track table access" This reverts commit 7684e6aa0750744e61cee0a29b948209c140d717. --- src/blua/lcode.c | 12 ------------ src/blua/lopcodes.h | 2 -- 2 files changed, 14 deletions(-) diff --git a/src/blua/lcode.c b/src/blua/lcode.c index 562ad3506..567b88500 100644 --- a/src/blua/lcode.c +++ b/src/blua/lcode.c @@ -626,20 +626,8 @@ static void codenot (FuncState *fs, expdesc *e) { removevalues(fs, e->t); } -/* -** Check whether expression 'e' is a literal string -*/ -static int isKstr (FuncState *fs, expdesc *e) { - return (e->k == VK && ttisstring(&fs->f->k[e->u.s.info])); -} -/* -** Create expression 't[k]'. 't' must have its final result already in a -** register or upvalue. Upvalues can only be indexed by literal strings. -*/ void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k) { - if (t->k == VUPVAL && !isKstr(fs, k)) /* upvalue indexed by non string? */ - luaK_exp2anyreg(fs, t); /* put it in a register */ t->u.s.aux = luaK_exp2RK(fs, k); t->k = VINDEXED; } diff --git a/src/blua/lopcodes.h b/src/blua/lopcodes.h index aa84da8d0..8b08b04e0 100644 --- a/src/blua/lopcodes.h +++ b/src/blua/lopcodes.h @@ -232,8 +232,6 @@ OP_VARARG/* A B R(A), R(A+1), ..., R(A+B-1) = vararg */ (*) In OP_SETLIST, if (B == 0) then B = `top'; if (C == 0) then next `instruction' is real C - (*) In OP_SELF, the index must be a string. - (*) For comparisons, A specifies what condition the test should accept (true or false). From 4fa937728b50cdb6b33d9bf2d1dab26059de50f8 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:42 +0200 Subject: [PATCH 03/11] Revert "Blua: OP_SELF can use 'luaV_fastget' specialized for strings, as it is applied only to string keys" This reverts commit 0fb752b7459673d8a3b38c917f9593602b03c4a0. --- src/blua/lvm.c | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/src/blua/lvm.c b/src/blua/lvm.c index 4d617d62c..9db792fd6 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -529,16 +529,11 @@ void luaV_execute (lua_State *L, int nexeccalls) { continue; } case OP_SELF: { - TValue *slot; StkId ra = RA(i); StkId rb = RB(i); TValue *rc = RKC(i); - TString *key = rawtsvalue(rc); /* key must be a string */ setobjs2s(L, ra + 1, rb); - if (luaV_fastget(L, rb, key, slot, luaH_getstr)) { - setobj2s(L, ra, slot); - } - else Protect(luaV_finishget(L, rb, rc, ra, slot)); + gettableProtected(L, rb, rc, ra); continue; } case OP_ADD: { From 8e82256827b12d6e90d9347a7800f225afcbd263 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:46 +0200 Subject: [PATCH 04/11] Revert "Blua: 'luaV_fastget' only treats the real fast case (table with a non-nil value at given key, so that it does not need to check metamethods)" This reverts commit 019812db0843e0d8a6678ae0ad13f018603d73a5. --- src/blua/lapi.c | 16 ++++++------ src/blua/lvm.c | 66 +++++++++++++++++++------------------------------ src/blua/lvm.h | 25 ++++++++++--------- 3 files changed, 46 insertions(+), 61 deletions(-) diff --git a/src/blua/lapi.c b/src/blua/lapi.c index bca24a90f..420e4e20b 100644 --- a/src/blua/lapi.c +++ b/src/blua/lapi.c @@ -520,17 +520,17 @@ LUA_API int lua_pushthread (lua_State *L) { */ static void auxgetstr (lua_State *L, TValue *t, const char *k) { - TValue *slot; + TValue *aux; TValue key; TString *str = luaS_new(L, k); api_checkvalidindex(L, t); - if (luaV_fastget(L, t, str, slot, luaH_getstr)) { - setobj2s(L, L->top, slot); + if (luaV_fastget(L, t, str, aux, luaH_getstr)) { + setobj2s(L, L->top, aux); api_incr_top(L); } else { setsvalue(L, &key, str); - luaV_finishget(L, t, L->top, L->top, slot); + luaV_finishget(L, t, L->top, L->top, aux); api_incr_top(L); } lua_unlock(L); @@ -643,17 +643,17 @@ LUA_API void lua_getfenv (lua_State *L, int idx) { static void auxsetstr (lua_State *L, TValue *t, const char *k) { TValue key; - TValue *slot; + TValue *aux; TString *str = luaS_new(L, k); api_checknelems(L, 1); api_checkvalidindex(L, t); - if (luaV_fastset(L, t, str, slot, luaH_setstr, L->top)) { - setobj2t(L, cast(TValue *, slot), L->top - 1); + if (luaV_fastset(L, t, str, aux, luaH_setstr, L->top)) { + setobj2t(L, cast(TValue *, aux), L->top - 1); L->top--; /* pop value */ } else { setsvalue2s(L, &key, str); - luaV_finishset(L, t, &key, L->top - 1, slot); + luaV_finishset(L, t, &key, L->top - 1, aux); L->top--; /* pop value */ } lua_unlock(L); diff --git a/src/blua/lvm.c b/src/blua/lvm.c index 9db792fd6..7540bcdec 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -106,67 +106,51 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1, /* -** Finish the table access 'val = t[key]'. -** if 'slot' is NULL, 't' is not a table; otherwise, 'slot' points to -** t[k] entry (which must be nil). +** Complete a table access: if 't' is a table, 'tm' has its metamethod; +** otherwise, 'tm' is NULL. */ void luaV_finishget (lua_State *L, TValue *t, TValue *key, StkId val, - TValue *slot) { + TValue *tm) { int loop; /* counter to avoid infinite loops */ - TValue *tm; /* metamethod */ + lua_assert(tm != NULL || !ttistable(t)); for (loop = 0; loop < MAXTAGLOOP; loop++) { - if (slot == NULL) { /* 't' is not a table? */ - lua_assert(!ttistable(t)); - tm = luaT_gettmbyobj(L, t, TM_INDEX); - if (l_unlikely(ttisnil(tm))) + if (tm == NULL) { /* no metamethod (from a table)? */ + if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))) luaG_typeerror(L, t, "index"); /* no metamethod */ - /* else will try the metamethod */ } - else { /* 't' is a table */ - lua_assert(ttisnil(slot)); - tm = fasttm(L, hvalue(t)->metatable, TM_INDEX); /* table's metamethod */ - if (tm == NULL) { /* no metamethod? */ - setnilvalue(val); /* result is nil */ - return; - } - /* else will try the metamethod */ - } - if (ttisfunction(tm)) { /* is metamethod a function? */ + if (ttisfunction(tm)) { /* metamethod is a function */ callTMres(L, val, tm, t, key); /* call it */ return; } - t = tm; /* else try to access 'tm[key]' */ - if (luaV_fastget(L,t,key,slot,luaH_get)) { /* fast track? */ - setobj2s(L, val, slot); /* done */ + t = tm; /* else repeat access over 'tm' */ + if (luaV_fastget(L,t,key,tm,luaH_get)) { /* try fast track */ + setobj2s(L, val, tm); /* done */ return; } - /* else repeat (tail call 'luaV_finishget') */ + /* else repeat */ } - luaG_runerror(L, "'__index' chain too long; possible loop"); + luaG_runerror(L, "gettable chain too long; possible loop"); } /* -** Finish a table assignment 't[key] = val'. -** If 'slot' is NULL, 't' is not a table. Otherwise, 'slot' points -** to the entry 't[key]', or to 'luaO_nilobject' if there is no such -** entry. (The value at 'slot' must be nil, otherwise 'luaV_fastset' -** would have done the job.) +** Main function for table assignment (invoking metamethods if needed). +** Compute 't[key] = val' */ void luaV_finishset (lua_State *L, TValue *t, TValue *key, - StkId val, TValue *slot) { + StkId val, TValue *oldval) { int loop; /* counter to avoid infinite loops */ for (loop = 0; loop < MAXTAGLOOP; loop++) { TValue *tm; - if (slot != NULL) { - lua_assert(ttistable(t) && ttisnil(slot)); + if (oldval != NULL) { + lua_assert(ttistable(t) && ttisnil(oldval)); Table *h = hvalue(t); /* must check the metamethod */ - /* slot is nil=> look for newindex, slot is not nil => look for usedindex */ - if (!((ttisnil(slot) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) || - ((!ttisnil(slot)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) { + /* oldval is nil=> look for newindex, oldval is not nil => look for usedindex */ + if (!((ttisnil(oldval) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) || + ((!ttisnil(oldval)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) { /* no metamethod and (now) there is an entry with given key */ - setobj2t(L, cast(TValue *, slot), val); + setobj2t(L, cast(TValue *, oldval), val); luaC_barriert(L, h, val); return; } @@ -182,7 +166,7 @@ void luaV_finishset (lua_State *L, TValue *t, TValue *key, return; } t = tm; /* else repeat assignment over 'tm' */ - if (luaV_fastset(L, t, key, slot, luaH_set, val)) + if (luaV_fastset(L, t, key, oldval, luaH_set, val)) return; /* done */ /* else loop */ } @@ -413,9 +397,9 @@ static void Arith (lua_State *L, StkId ra, TValue *rb, ** copy of 'luaV_gettable', but protecting call to potential metamethod ** (which can reallocate the stack) */ -#define gettableProtected(L,t,k,v) { TValue *slot; \ - if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ - else Protect(luaV_finishget(L,t,k,v,slot)); } +#define gettableProtected(L,t,k,v) { TValue *aux; \ + if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \ + else Protect(luaV_finishget(L,t,k,v,aux)); } /* same for 'luaV_settable' */ diff --git a/src/blua/lvm.h b/src/blua/lvm.h index 0c4c877f2..2f65098f0 100644 --- a/src/blua/lvm.h +++ b/src/blua/lvm.h @@ -23,24 +23,25 @@ /* -** fast track for 'gettable': if 't' is a table and 't[k]' is not nil, -** return 1 with 'slot' pointing to 't[k]' (final result). Otherwise, -** return 0 (meaning it will have to check metamethod) with 'slot' -** pointing to a nil 't[k]' (if 't' is a table) or NULL (otherwise). -** 'f' is the raw get function to use. +** fast track for 'gettable': 1 means 'aux' points to resulted value; +** 0 means 'aux' is metamethod (if 't' is a table) or NULL. 'f' is +** the raw get function to use. */ -#define luaV_fastget(L,t,k,slot,f) \ +#define luaV_fastget(L,t,k,aux,f) \ (!ttistable(t) \ - ? (slot = NULL, 0) /* not a table; 'slot' is NULL and result is 0 */ \ - : (slot = f(hvalue(t), k), /* else, do raw access */ \ - !ttisnil(slot))) /* result not nil? */ + ? (aux = NULL, 0) /* not a table; 'aux' is NULL and result is 0 */ \ + : (aux = f(hvalue(t), k), /* else, do raw access */ \ + !ttisnil(aux) ? 1 /* result not nil? 'aux' has it */ \ + : (aux = fasttm(L, hvalue(t)->metatable, TM_INDEX), /* get metamethod */\ + aux != NULL ? 0 /* has metamethod? must call it */ \ + : (aux = luaO_nilobject, 1)))) /* else, final result is nil */ /* ** standard implementation for 'gettable' */ -#define luaV_gettable(L,t,k,v) { TValue *slot; \ - if (luaV_fastget(L,t,k,slot,luaH_get)) { setobj2s(L, v, slot); } \ - else luaV_finishget(L,t,k,v,slot); } +#define luaV_gettable(L,t,k,v) { TValue *aux; \ + if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \ + else luaV_finishget(L,t,k,v,aux); } /* From 2b650e4b6142b9facea3416f89bc7bf7d7c7ac31 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:53 +0200 Subject: [PATCH 05/11] Revert "Blua: 'Protect' in table operations is not needed in the fast track" This reverts commit 537a50b9b3d7f33d95e142910ef5880cc8cc57cf. --- src/blua/lvm.c | 30 +++++++----------------------- 1 file changed, 7 insertions(+), 23 deletions(-) diff --git a/src/blua/lvm.c b/src/blua/lvm.c index 7540bcdec..484329825 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -393,21 +393,6 @@ static void Arith (lua_State *L, StkId ra, TValue *rb, } -/* -** copy of 'luaV_gettable', but protecting call to potential metamethod -** (which can reallocate the stack) -*/ -#define gettableProtected(L,t,k,v) { TValue *aux; \ - if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \ - else Protect(luaV_finishget(L,t,k,v,aux)); } - - -/* same for 'luaV_settable' */ -#define settableProtected(L,t,k,v) { TValue *slot; \ - if (!luaV_fastset(L,t,k,slot,luaH_set,v)) \ - Protect(luaV_finishset(L,t,k,v,slot)); } - - void luaV_execute (lua_State *L, int nexeccalls) { LClosure *cl; @@ -417,9 +402,9 @@ void luaV_execute (lua_State *L, int nexeccalls) { reentry: /* entry point */ lua_assert(isLua(L->ci)); pc = L->savedpc; - cl = &clvalue(L->ci->func)->l; /* local reference to function's closure */ - k = cl->p->k; /* local reference to function's constant table */ - base = L->base; /* local copy of function's base */ + cl = &clvalue(L->ci->func)->l; + base = L->base; + k = cl->p->k; /* main loop of interpreter */ for (;;) { const Instruction i = *pc++; @@ -479,7 +464,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { StkId ra = RA(i); StkId rb = RB(i); TValue *rc = RKC(i); - gettableProtected(L, rb, rc, ra); + Protect(luaV_gettable(L, rb, rc, ra)); continue; } case OP_SETGLOBAL: { @@ -501,7 +486,7 @@ void luaV_execute (lua_State *L, int nexeccalls) { StkId ra = RA(i); TValue *rb = RKB(i); TValue *rc = RKC(i); - settableProtected(L, ra, rb, rc); + Protect(luaV_settable(L, ra, rb, rc)); continue; } case OP_NEWTABLE: { @@ -515,9 +500,8 @@ void luaV_execute (lua_State *L, int nexeccalls) { case OP_SELF: { StkId ra = RA(i); StkId rb = RB(i); - TValue *rc = RKC(i); - setobjs2s(L, ra + 1, rb); - gettableProtected(L, rb, rc, ra); + setobjs2s(L, ra+1, rb); + Protect(luaV_gettable(L, rb, RKC(i), ra)); continue; } case OP_ADD: { From bd27a6276900d81fa1d232f9b9724cbc6b5ffc14 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:53:59 +0200 Subject: [PATCH 06/11] Revert "Blua: fast track for 'settable'" This reverts commit bdae0ef4aec9e01de1e15593e49499dbb93267aa. --- src/blua/lapi.c | 29 +++++++++-------------------- src/blua/lvm.c | 36 +++++++++++------------------------- src/blua/lvm.h | 30 ++---------------------------- 3 files changed, 22 insertions(+), 73 deletions(-) diff --git a/src/blua/lapi.c b/src/blua/lapi.c index 420e4e20b..990e17b6e 100644 --- a/src/blua/lapi.c +++ b/src/blua/lapi.c @@ -641,25 +641,6 @@ LUA_API void lua_getfenv (lua_State *L, int idx) { */ -static void auxsetstr (lua_State *L, TValue *t, const char *k) { - TValue key; - TValue *aux; - TString *str = luaS_new(L, k); - api_checknelems(L, 1); - api_checkvalidindex(L, t); - if (luaV_fastset(L, t, str, aux, luaH_setstr, L->top)) { - setobj2t(L, cast(TValue *, aux), L->top - 1); - L->top--; /* pop value */ - } - else { - setsvalue2s(L, &key, str); - luaV_finishset(L, t, &key, L->top - 1, aux); - L->top--; /* pop value */ - } - lua_unlock(L); -} - - LUA_API void lua_settable (lua_State *L, int idx) { StkId t; lua_lock(L); @@ -673,8 +654,16 @@ LUA_API void lua_settable (lua_State *L, int idx) { LUA_API void lua_setfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; lua_lock(L); - auxsetstr(L, index2adr(L, idx), k); + api_checknelems(L, 1); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_settable(L, t, &key, L->top - 1); + L->top--; /* pop value */ + lua_unlock(L); } diff --git a/src/blua/lvm.c b/src/blua/lvm.c index 484329825..64e670d2f 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -132,45 +132,31 @@ void luaV_finishget (lua_State *L, TValue *t, TValue *key, StkId val, luaG_runerror(L, "gettable chain too long; possible loop"); } - -/* -** Main function for table assignment (invoking metamethods if needed). -** Compute 't[key] = val' -*/ -void luaV_finishset (lua_State *L, TValue *t, TValue *key, - StkId val, TValue *oldval) { - int loop; /* counter to avoid infinite loops */ +void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val) { + int loop; for (loop = 0; loop < MAXTAGLOOP; loop++) { - TValue *tm; - if (oldval != NULL) { - lua_assert(ttistable(t) && ttisnil(oldval)); + TValue *tm = NULL; + if (ttistable(t)) { /* `t' is a table? */ Table *h = hvalue(t); - /* must check the metamethod */ + TValue *oldval = luaH_set(L, h, key); /* do a primitive set */ /* oldval is nil=> look for newindex, oldval is not nil => look for usedindex */ if (!((ttisnil(oldval) && ((tm = fasttm(L, h->metatable, TM_NEWINDEX)) != NULL)) || ((!ttisnil(oldval)) && ((tm = fasttm(L, h->metatable, TM_USEDINDEX)) != NULL)))) { - /* no metamethod and (now) there is an entry with given key */ - setobj2t(L, cast(TValue *, oldval), val); + setobj2t(L, oldval, val); luaC_barriert(L, h, val); return; } - /* else will try the metamethod */ + /* else will try the tag method */ } - else { /* not a table; check metamethod */ - if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))) - luaG_typeerror(L, t, "index"); - } - /* try the metamethod */ + else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_NEWINDEX)))) + luaG_typeerror(L, t, "index"); if (ttisfunction(tm)) { callTM(L, tm, t, key, val); return; } - t = tm; /* else repeat assignment over 'tm' */ - if (luaV_fastset(L, t, key, oldval, luaH_set, val)) - return; /* done */ - /* else loop */ + t = tm; /* else repeat with `tm' */ } - luaG_runerror(L, "settable chain too long; possible loop"); + luaG_runerror(L, "loop in settable"); } diff --git a/src/blua/lvm.h b/src/blua/lvm.h index 2f65098f0..2ffc80ace 100644 --- a/src/blua/lvm.h +++ b/src/blua/lvm.h @@ -44,32 +44,6 @@ else luaV_finishget(L,t,k,v,aux); } -/* -** Fast track for set table. If 't' is a table and 't[k]' is not nil, -** call GC barrier, do a raw 't[k]=v', and return true; otherwise, -** return false with 'slot' equal to NULL (if 't' is not a table) or -** 'nil'. (This is needed by 'luaV_finishget'.) Note that, if the macro -** returns true, there is no need to 'invalidateTMcache', because the -** call is not creating a new entry. -*/ -#define luaV_fastset(L,t,k,slot,f,v) \ - (!ttistable(t) \ - ? (slot = NULL, 0) \ - : (slot = f(L, hvalue(t), k), \ - ttisnil(slot) ? 0 \ - : (__extension__ ({ \ - if (valiswhite(v) && isblack(obj2gco(hvalue(t)))) \ - luaC_barrierback(L, hvalue(t)); \ - setobj2t(L, cast(TValue *,slot), v); \ - 1; \ - })))) - - -#define luaV_settable(L,t,k,v) { TValue *slot; \ - if (!luaV_fastset(L,t,k,slot,luaH_set,v)) \ - luaV_finishset(L,t,k,v,slot); } - - LUAI_FUNC int luaV_lessthan (lua_State *L, TValue *l, TValue *r); LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); @@ -77,8 +51,8 @@ LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); LUAI_FUNC void luaV_finishget (lua_State *L, TValue *t, TValue *key, StkId val, TValue *tm); -LUAI_FUNC void luaV_finishset (lua_State *L, TValue *t, TValue *key, - StkId val, TValue *oldval); +LUAI_FUNC void luaV_settable (lua_State *L, TValue *t, TValue *key, + StkId val); LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); LUAI_FUNC void luaV_concat (lua_State *L, int total, int last); From e7332a3efe77a651f2c122df07642ae3d8033fa5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 11:54:10 +0200 Subject: [PATCH 07/11] Revert "Blua: implementation of fast track for gettable operations" This reverts commit e4e51f0f80fb7deb9213c72bb374d0a7e4c3f03b. --- src/blua/lapi.c | 26 ++++++++------------------ src/blua/lvm.c | 39 +++++++++++++++++++-------------------- src/blua/lvm.h | 27 ++------------------------- 3 files changed, 29 insertions(+), 63 deletions(-) diff --git a/src/blua/lapi.c b/src/blua/lapi.c index 990e17b6e..6a33983fe 100644 --- a/src/blua/lapi.c +++ b/src/blua/lapi.c @@ -519,23 +519,6 @@ LUA_API int lua_pushthread (lua_State *L) { ** get functions (Lua -> stack) */ -static void auxgetstr (lua_State *L, TValue *t, const char *k) { - TValue *aux; - TValue key; - TString *str = luaS_new(L, k); - api_checkvalidindex(L, t); - if (luaV_fastget(L, t, str, aux, luaH_getstr)) { - setobj2s(L, L->top, aux); - api_incr_top(L); - } - else { - setsvalue(L, &key, str); - luaV_finishget(L, t, L->top, L->top, aux); - api_incr_top(L); - } - lua_unlock(L); -} - LUA_API void lua_gettable (lua_State *L, int idx) { StkId t; @@ -548,8 +531,15 @@ LUA_API void lua_gettable (lua_State *L, int idx) { LUA_API void lua_getfield (lua_State *L, int idx, const char *k) { + StkId t; + TValue key; lua_lock(L); - auxgetstr(L, index2adr(L, idx), k); + t = index2adr(L, idx); + api_checkvalidindex(L, t); + setsvalue(L, &key, luaS_new(L, k)); + luaV_gettable(L, t, &key, L->top); + api_incr_top(L); + lua_unlock(L); } diff --git a/src/blua/lvm.c b/src/blua/lvm.c index 64e670d2f..7afbbd572 100644 --- a/src/blua/lvm.c +++ b/src/blua/lvm.c @@ -105,33 +105,32 @@ static void callTM (lua_State *L, const TValue *f, const TValue *p1, } -/* -** Complete a table access: if 't' is a table, 'tm' has its metamethod; -** otherwise, 'tm' is NULL. -*/ -void luaV_finishget (lua_State *L, TValue *t, TValue *key, StkId val, - TValue *tm) { - int loop; /* counter to avoid infinite loops */ - lua_assert(tm != NULL || !ttistable(t)); +void luaV_gettable (lua_State *L, TValue *t, TValue *key, StkId val) { + int loop; for (loop = 0; loop < MAXTAGLOOP; loop++) { - if (tm == NULL) { /* no metamethod (from a table)? */ - if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))) - luaG_typeerror(L, t, "index"); /* no metamethod */ + TValue *tm; + if (ttistable(t)) { /* `t' is a table? */ + Table *h = hvalue(t); + const TValue *res = luaH_get(h, key); /* do a primitive get */ + if (!ttisnil(res) || /* result is no nil? */ + (tm = fasttm(L, h->metatable, TM_INDEX)) == NULL) { /* or no TM? */ + setobj2s(L, val, res); + return; + } + /* else will try the tag method */ } - if (ttisfunction(tm)) { /* metamethod is a function */ - callTMres(L, val, tm, t, key); /* call it */ + else if (l_unlikely(ttisnil(tm = luaT_gettmbyobj(L, t, TM_INDEX)))) + luaG_typeerror(L, t, "index"); + if (ttisfunction(tm)) { + callTMres(L, val, tm, t, key); return; } - t = tm; /* else repeat access over 'tm' */ - if (luaV_fastget(L,t,key,tm,luaH_get)) { /* try fast track */ - setobj2s(L, val, tm); /* done */ - return; - } - /* else repeat */ + t = tm; /* else repeat with `tm' */ } - luaG_runerror(L, "gettable chain too long; possible loop"); + luaG_runerror(L, "loop in gettable"); } + void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val) { int loop; for (loop = 0; loop < MAXTAGLOOP; loop++) { diff --git a/src/blua/lvm.h b/src/blua/lvm.h index 2ffc80ace..f9226ee5d 100644 --- a/src/blua/lvm.h +++ b/src/blua/lvm.h @@ -22,35 +22,12 @@ (ttype(o1) == ttype(o2) && luaV_equalval(L, o1, o2)) -/* -** fast track for 'gettable': 1 means 'aux' points to resulted value; -** 0 means 'aux' is metamethod (if 't' is a table) or NULL. 'f' is -** the raw get function to use. -*/ -#define luaV_fastget(L,t,k,aux,f) \ - (!ttistable(t) \ - ? (aux = NULL, 0) /* not a table; 'aux' is NULL and result is 0 */ \ - : (aux = f(hvalue(t), k), /* else, do raw access */ \ - !ttisnil(aux) ? 1 /* result not nil? 'aux' has it */ \ - : (aux = fasttm(L, hvalue(t)->metatable, TM_INDEX), /* get metamethod */\ - aux != NULL ? 0 /* has metamethod? must call it */ \ - : (aux = luaO_nilobject, 1)))) /* else, final result is nil */ - -/* -** standard implementation for 'gettable' -*/ -#define luaV_gettable(L,t,k,v) { TValue *aux; \ - if (luaV_fastget(L,t,k,aux,luaH_get)) { setobj2s(L, v, aux); } \ - else luaV_finishget(L,t,k,v,aux); } - - - LUAI_FUNC int luaV_lessthan (lua_State *L, TValue *l, TValue *r); LUAI_FUNC int luaV_equalval (lua_State *L, const TValue *t1, const TValue *t2); LUAI_FUNC const TValue *luaV_tonumber (const TValue *obj, TValue *n); LUAI_FUNC int luaV_tostring (lua_State *L, StkId obj); -LUAI_FUNC void luaV_finishget (lua_State *L, TValue *t, TValue *key, - StkId val, TValue *tm); +LUAI_FUNC void luaV_gettable (lua_State *L, TValue *t, TValue *key, + StkId val); LUAI_FUNC void luaV_settable (lua_State *L, TValue *t, TValue *key, StkId val); LUAI_FUNC void luaV_execute (lua_State *L, int nexeccalls); From f82d1384828d7a6eb55ee27f5e8571f9dc291d8a Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 15 May 2026 13:00:24 +0200 Subject: [PATCH 08/11] cleanup some things --- src/hardware/hw_main.cpp | 2 +- src/k_hud.c | 2 +- src/p_mobj.c | 12 ++++++------ src/r_bsp.cpp | 12 +++++++----- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 2587055c5..86efff5ba 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -696,7 +696,7 @@ static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, bool vert->z = (vy);\ \ } - for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++,v3d++, pv++) + for (i = 0, v3d = planeVerts; i < (INT32)nrPlaneVerts; i++, v3d++, pv++) SETUP3DVERT(v3d, pv->x, pv->y); if (slope) diff --git a/src/k_hud.c b/src/k_hud.c index ebbf2d0b2..4e930023c 100644 --- a/src/k_hud.c +++ b/src/k_hud.c @@ -4448,7 +4448,7 @@ static void K_drawLapStartAnim(void) char *lapnum = va("%02d", stplyr->laps + 1); const size_t laplength = strlen(lapnum); - for (int i = 0; i < (int)laplength; i++) + for (size_t i = 0; i < laplength; i++) { int digit = lapnum[i] - '0'; int frame = min(2, progress/2 - 8 - (i*2)); diff --git a/src/p_mobj.c b/src/p_mobj.c index d9b4a08ba..96a8e11d5 100644 --- a/src/p_mobj.c +++ b/src/p_mobj.c @@ -905,7 +905,12 @@ static void P_PlayerFlip(mobj_t *mo) G_GhostAddFlip((INT32) (mo->player - players)); // Flip aiming to match! - if (mo->player->pflags & PF_FLIPCAM) + if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam + { + if (mo->tracer) + mo->tracer->eflags ^= MFE_VERTICALFLIP; + } + else if (mo->player->pflags & PF_FLIPCAM) { UINT8 i; @@ -927,11 +932,6 @@ static void P_PlayerFlip(mobj_t *mo) camera[i].z += FixedMul(20*FRACUNIT, mo->scale); } } - else if (UNLIKELY(mo->player->pflags & PF_NIGHTSMODE)) // NiGHTS doesn't use flipcam - { - if (mo->tracer) - mo->tracer->eflags ^= MFE_VERTICALFLIP; - } } // diff --git a/src/r_bsp.cpp b/src/r_bsp.cpp index 60d84c57f..a3e67a5e3 100644 --- a/src/r_bsp.cpp +++ b/src/r_bsp.cpp @@ -221,8 +221,9 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, tempsec->floorheight = s->floorheight; tempsec->ceilingheight = s->ceilingheight; - if ((underwater && (tempsec-> floorheight = sec->floorheight, - tempsec->ceilingheight = s->floorheight - 1, !back)) || viewz <= s->floorheight) + if ((underwater && (tempsec->floorheight = sec->floorheight, + tempsec->ceilingheight = s->floorheight - 1, !back)) || + viewz <= s->floorheight) { // head-below-floor hack tempsec->floorpic = s->floorpic; tempsec->floor_xoffs = s->floor_xoffs; @@ -258,8 +259,8 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, *ceilinglightlevel = s->ceilinglightsec == -1 ? s->lightlevel : sectors[s->ceilinglightsec].lightlevel; } - else if (heightsec != -1 && viewz >= sectors[heightsec].ceilingheight - && sec->ceilingheight > s->ceilingheight) + else if (heightsec != -1 && viewz >= sectors[heightsec].ceilingheight && + sec->ceilingheight > s->ceilingheight) { // Above-ceiling hack tempsec->ceilingheight = s->ceilingheight; tempsec->floorheight = s->ceilingheight + 1; @@ -296,7 +297,8 @@ sector_t *R_FakeFlat(sector_t *sec, sector_t *tempsec, INT32 *floorlightlevel, *ceilinglightlevel = s->ceilinglightsec == -1 ? s->lightlevel : sectors[s->ceilinglightsec].lightlevel; } - sec = tempsec; + + sec = tempsec; // Use other sector } return sec; From da103f54d6b5a80b432bcc129aba8361a2b7f08d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 18 May 2026 18:20:58 +0200 Subject: [PATCH 09/11] hw_main: reorder plane stuff in HWR_Subsector check for subsector validcount first, then if its a sky plane so we can skip checking sector heights for sky planes, which may save a bit of maths on maps with many slopes --- src/hardware/hw_main.cpp | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 86efff5ba..3f4ccf23e 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2977,9 +2977,6 @@ static void HWR_Subsector(size_t num) floorcolormap = ceilingcolormap = gl_frontsector->extra_colormap; - cullFloorHeight = P_GetSectorFloorZAt (gl_frontsector, viewx, viewy); - cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy); - if (gl_frontsector->ffloors) { locFloorHeight = P_GetSectorFloorZAt (gl_frontsector, gl_frontsector->soundorg.x, gl_frontsector->soundorg.y); @@ -3029,13 +3026,15 @@ static void HWR_Subsector(size_t num) sub->sector->extra_colormap = gl_frontsector->extra_colormap; - // render floor ? - // yeah, easy backface cull! :) - if (cullFloorHeight < viewz) + if (sub->validcount != validcount) { if (gl_frontsector->floorpic != skyflatnum) { - if (sub->validcount != validcount) + cullFloorHeight = P_GetSectorFloorZAt(gl_frontsector, viewx, viewy); + + // render floor ? + // yeah, easy backface cull! :) + if (cullFloorHeight < viewz) { HWR_GetFlat(levelflats[gl_frontsector->floorpic].lumpnum, R_NoEncore(gl_frontsector, false)); HWR_RenderPlane(sub, &extrasubsectors[num], false, @@ -3044,13 +3043,12 @@ static void HWR_Subsector(size_t num) PF_Occlude, floorlightlevel, levelflats[gl_frontsector->floorpic].lumpnum, NULL, 255, floorcolormap); } } - } - if (cullCeilingHeight > viewz) - { if (gl_frontsector->ceilingpic != skyflatnum) { - if (sub->validcount != validcount) + cullCeilingHeight = P_GetSectorCeilingZAt(gl_frontsector, viewx, viewy); + + if (cullCeilingHeight > viewz) { HWR_GetFlat(levelflats[gl_frontsector->ceilingpic].lumpnum, R_NoEncore(gl_frontsector, true)); HWR_RenderPlane(sub, &extrasubsectors[num], true, @@ -3070,6 +3068,7 @@ static void HWR_Subsector(size_t num) if (!(rover->flags & FF_EXISTS) || !(rover->flags & FF_RENDERPLANES) || !(rover->flags & FF_RENDERALL)) continue; + if (sub->validcount == validcount) continue; From b5c7fd5a2b69388bdfada42c1384f889b38183e2 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 18 May 2026 18:00:40 +0200 Subject: [PATCH 10/11] HWR_Subsector: check for sub->polyList instead of numpolys numpolys sometimes might not get reset, checking for sub->polyList is what was actually intended --- src/hardware/hw_main.cpp | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/hardware/hw_main.cpp b/src/hardware/hw_main.cpp index 3f4ccf23e..5a45090de 100644 --- a/src/hardware/hw_main.cpp +++ b/src/hardware/hw_main.cpp @@ -2632,7 +2632,6 @@ static boolean HWR_CheckBBox(const fixed_t *bspcoord) return gld_clipper_SafeCheckRange(angle2, angle1); } - // // HWR_AddPolyObjectSegs // @@ -3231,11 +3230,11 @@ doaddline: // without talking about the overdraw of course. sub->sector->validcount = validcount;/// \todo fix that in a better way - if (UNLIKELY(numpolys)) + if (UNLIKELY(sub->polyList)) { while (count--) { - if (LIKELY(!line->polyseg)) // ignore segs that belong to polyobjects + if (!line->polyseg) // ignore segs that belong to polyobjects { HWR_AddLine(line); } From ac86f36186a5e3c0735389e4524d5968171da7b3 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 18 May 2026 20:31:46 +0300 Subject: [PATCH 11/11] Skip empty lines in renderer.txt --- src/sdl/i_video.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index aa0c5c72d..a30da7f0a 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -1855,6 +1855,9 @@ void I_StartupGraphics(void) { word = strtok(line, " \n"); + if (!word) + continue; + if (rendermode == render_none) { if (fasticmp(word, "software"))