From 8bcada1fda32df7d7f901b74e65c57508a259b71 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 3 Dec 2025 19:28:57 +0100 Subject: [PATCH] Blua: opcode OP_SELF operate only with string keys, so they can use fast-track table access https://github.com/lua/lua/commit/cb3d5dce30089512085f78a0bef79e30ef732e30 --- src/blua/lcode.c | 12 ++++++++++++ src/blua/lopcodes.h | 2 ++ 2 files changed, 14 insertions(+) diff --git a/src/blua/lcode.c b/src/blua/lcode.c index 567b88500..562ad3506 100644 --- a/src/blua/lcode.c +++ b/src/blua/lcode.c @@ -626,8 +626,20 @@ 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 8b08b04e0..aa84da8d0 100644 --- a/src/blua/lopcodes.h +++ b/src/blua/lopcodes.h @@ -232,6 +232,8 @@ 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).