Skip to content

Commit d297b0a

Browse files
committed
Phase 122: Remove setfltvalue, chgfltvalue, setivalue, chgivalue macros
Replace legacy wrapper macros with direct TValue member function calls: - setfltvalue(obj, x) → obj->setFloat(x) - chgfltvalue(obj, x) → obj->changeFloat(x) - setivalue(obj, x) → obj->setInt(x) - chgivalue(obj, x) → obj->changeInt(x) Changes: - Updated 60+ callsites across 12 files - Removed 4 wrapper function definitions from lobject_core.h - All calls now use direct TValue member functions Benefits: - Cleaner, more object-oriented API - Consistent with project's macro elimination goal - No performance impact (functions are inline) Performance: 4.31s avg (target ≤4.33s, baseline 4.20s) ✅ Tests: All passing ✅
1 parent e7c5e88 commit d297b0a

File tree

12 files changed

+58
-63
lines changed

12 files changed

+58
-63
lines changed

src/compiler/lcode.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ static int tonumeral (const expdesc *e, TValue *v) {
5353
return 0; /* not a numeral */
5454
switch (e->getKind()) {
5555
case VKINT:
56-
if (v) setivalue(v, e->getIntValue());
56+
if (v) v->setInt(e->getIntValue());
5757
return 1;
5858
case VKFLT:
59-
if (v) setfltvalue(v, e->getFloatValue());
59+
if (v) v->setFloat(e->getFloatValue());
6060
return 1;
6161
default: return 0;
6262
}
@@ -348,7 +348,7 @@ int FuncState::k2proto(TValue *key, TValue *v) {
348348
int k = addk(proto, v);
349349
/* cache it for reuse; numerical value does not need GC barrier;
350350
table is not a metatable, so it does not need to invalidate cache */
351-
setivalue(&val, k);
351+
val.setInt(k);
352352
luaH_set(getLexState()->getLuaState(), getKCache(), key, &val);
353353
return k;
354354
}
@@ -368,7 +368,7 @@ int FuncState::stringK(TString *s) {
368368
*/
369369
int FuncState::intK(lua_Integer n) {
370370
TValue o;
371-
setivalue(&o, n);
371+
o.setInt(n);
372372
return k2proto(&o, &o); /* use integer itself as key */
373373
}
374374

@@ -386,7 +386,7 @@ int FuncState::intK(lua_Integer n) {
386386
*/
387387
int FuncState::numberK(lua_Number r) {
388388
TValue o, kv;
389-
setfltvalue(&o, r); /* value as a TValue */
389+
o.setFloat(r); /* value as a TValue */
390390
if (r == 0) { /* handle zero as a special case */
391391
setpvalue(&kv, this); /* use FuncState as index */
392392
return k2proto(&kv, &o); /* cannot collide */
@@ -396,7 +396,7 @@ int FuncState::numberK(lua_Number r) {
396396
const lua_Number q = l_mathop(ldexp)(l_mathop(1.0), -nbm + 1);
397397
const lua_Number k = r * (1 + q); /* key */
398398
lua_Integer ik;
399-
setfltvalue(&kv, k); /* key as a TValue */
399+
kv.setFloat(k); /* key as a TValue */
400400
if (!luaV_flttointeger(k, &ik, F2Imod::F2Ieq)) { /* not an integer value? */
401401
int n = k2proto(&kv, &o); /* use key */
402402
if (luaV_rawequalobj(&getProto()->getConstants()[n], &o)) /* correct value? */

src/core/lapi.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -467,15 +467,15 @@ LUA_API void lua_pushnil (lua_State *L) {
467467

468468
LUA_API void lua_pushnumber (lua_State *L, lua_Number n) {
469469
lua_lock(L);
470-
setfltvalue(s2v(L->getTop().p), n);
470+
s2v(L->getTop().p)->setFloat(n);
471471
api_incr_top(L);
472472
lua_unlock(L);
473473
}
474474

475475

476476
LUA_API void lua_pushinteger (lua_State *L, lua_Integer n) {
477477
lua_lock(L);
478-
setivalue(s2v(L->getTop().p), n);
478+
s2v(L->getTop().p)->setInt(n);
479479
api_incr_top(L);
480480
lua_unlock(L);
481481
}
@@ -673,7 +673,7 @@ LUA_API int lua_geti (lua_State *L, int idx, lua_Integer n) {
673673
luaV_fastgeti(t, n, s2v(L->getTop().p), tag);
674674
if (tagisempty(tag)) {
675675
TValue key;
676-
setivalue(&key, n);
676+
key.setInt(n);
677677
tag = luaV_finishget(L, t, &key, L->getTop().p, tag);
678678
}
679679
api_incr_top(L);
@@ -849,7 +849,7 @@ LUA_API void lua_seti (lua_State *L, int idx, lua_Integer n) {
849849
luaV_finishfastset(L, t, s2v(L->getTop().p - 1));
850850
else {
851851
TValue temp;
852-
setivalue(&temp, n);
852+
temp.setInt(n);
853853
luaV_finishset(L, t, &temp, s2v(L->getTop().p - 1), hres);
854854
}
855855
L->getStackSubsystem().pop(); /* pop value */

src/core/lstate.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,7 @@ LUA_API lua_State *lua_newstate (lua_Alloc f, void *ud, unsigned seed) {
367367
g->setGCTotalBytes(sizeof(global_State));
368368
g->setGCMarked(0);
369369
g->setGCDebt(0);
370-
setivalue(g->getNilValue(), 0); /* to signal that state is not yet built */
370+
g->getNilValue()->setInt(0); /* to signal that state is not yet built */
371371
setgcparam(g, PAUSE, LUAI_GCPAUSE);
372372
setgcparam(g, STEPMUL, LUAI_GCMUL);
373373
setgcparam(g, STEPSIZE, LUAI_GCSTEPSIZE);

src/core/ltm.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ void luaT_trybinassocTM (lua_State *L, const TValue *p1, const TValue *p2,
190190
void luaT_trybiniTM (lua_State *L, const TValue *p1, lua_Integer i2,
191191
int flip, StkId res, TMS event) {
192192
TValue aux;
193-
setivalue(&aux, i2);
193+
aux.setInt(i2);
194194
luaT_trybinassocTM(L, p1, &aux, flip, res, event);
195195
}
196196

@@ -212,10 +212,10 @@ int luaT_callorderiTM (lua_State *L, const TValue *p1, int v2,
212212
int flip, int isfloat, TMS event) {
213213
TValue aux; const TValue *p2;
214214
if (isfloat) {
215-
setfltvalue(&aux, cast_num(v2));
215+
aux.setFloat(cast_num(v2));
216216
}
217217
else
218-
setivalue(&aux, v2);
218+
aux.setInt(v2);
219219
if (flip) { /* arguments were exchanged? */
220220
p2 = p1; p1 = &aux; /* correct them */
221221
}

src/objects/lobject.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,27 @@ int luaO_rawarith (lua_State *L, int op, const TValue *p1, const TValue *p2,
159159
case LUA_OPBNOT: { /* operate only on integers */
160160
lua_Integer i1; lua_Integer i2;
161161
if (tointegerns(p1, &i1) && tointegerns(p2, &i2)) {
162-
setivalue(res, intarith(L, op, i1, i2));
162+
res->setInt(intarith(L, op, i1, i2));
163163
return 1;
164164
}
165165
else return 0; /* fail */
166166
}
167167
case LUA_OPDIV: case LUA_OPPOW: { /* operate only on floats */
168168
lua_Number n1; lua_Number n2;
169169
if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
170-
setfltvalue(res, numarith(L, op, n1, n2));
170+
res->setFloat(numarith(L, op, n1, n2));
171171
return 1;
172172
}
173173
else return 0; /* fail */
174174
}
175175
default: { /* other operations */
176176
lua_Number n1; lua_Number n2;
177177
if (ttisinteger(p1) && ttisinteger(p2)) {
178-
setivalue(res, intarith(L, op, ivalue(p1), ivalue(p2)));
178+
res->setInt(intarith(L, op, ivalue(p1), ivalue(p2)));
179179
return 1;
180180
}
181181
else if (tonumberns(p1, n1) && tonumberns(p2, n2)) {
182-
setfltvalue(res, numarith(L, op, n1, n2));
182+
res->setFloat(numarith(L, op, n1, n2));
183183
return 1;
184184
}
185185
else return 0; /* fail */
@@ -372,10 +372,10 @@ size_t luaO_str2num (const char *s, TValue *o) {
372372
lua_Integer i; lua_Number n;
373373
const char *e;
374374
if ((e = l_str2int(s, &i)) != nullptr) { /* try as an integer */
375-
setivalue(o, i);
375+
o->setInt(i);
376376
}
377377
else if ((e = l_str2d(s, &n)) != nullptr) { /* else try as a float */
378-
setfltvalue(o, n);
378+
o->setFloat(n);
379379
}
380380
else
381381
return 0; /* conversion failed */
@@ -608,19 +608,19 @@ const char *luaO_pushvfstring (lua_State *L, const char *fmt, va_list argp) {
608608
}
609609
case 'd': { /* an 'int' */
610610
TValue num;
611-
setivalue(&num, va_arg(argp, int));
611+
num.setInt(va_arg(argp, int));
612612
addnum2buff(&buff, &num);
613613
break;
614614
}
615615
case 'I': { /* a 'lua_Integer' */
616616
TValue num;
617-
setivalue(&num, cast_Integer(va_arg(argp, l_uacInt)));
617+
num.setInt(cast_Integer(va_arg(argp, l_uacInt)));
618618
addnum2buff(&buff, &num);
619619
break;
620620
}
621621
case 'f': { /* a 'lua_Number' */
622622
TValue num;
623-
setfltvalue(&num, cast_num(va_arg(argp, l_uacNumber)));
623+
num.setFloat(cast_num(va_arg(argp, l_uacNumber)));
624624
addnum2buff(&buff, &num);
625625
break;
626626
}

src/objects/lobject_core.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -192,11 +192,6 @@ inline lua_Integer ivalue(const TValue* o) noexcept { return o->intValue(); }
192192
constexpr lua_Number fltvalueraw(const Value& v) noexcept { return v.n; }
193193
constexpr lua_Integer ivalueraw(const Value& v) noexcept { return v.i; }
194194

195-
inline void setfltvalue(TValue* obj, lua_Number x) noexcept { obj->setFloat(x); }
196-
inline void chgfltvalue(TValue* obj, lua_Number x) noexcept { obj->changeFloat(x); }
197-
inline void setivalue(TValue* obj, lua_Integer x) noexcept { obj->setInt(x); }
198-
inline void chgivalue(TValue* obj, lua_Integer x) noexcept { obj->changeInt(x); }
199-
200195
/* }================================================================== */
201196

202197

src/objects/ltable.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ int luaH_next (lua_State *L, Table *t, StkId key) {
497497
for (; i < asize; i++) { /* try first array part */
498498
lu_byte tag = *t->getArrayTag(i);
499499
if (!tagisempty(tag)) { /* a non-empty entry? */
500-
setivalue(s2v(key), cast_int(i) + 1);
500+
s2v(key)->setInt(cast_int(i) + 1);
501501
farr2val(t, i, tag, s2v(key + 1));
502502
return 1;
503503
}
@@ -816,7 +816,7 @@ static void reinsertOldSlice (Table *t, unsigned oldasize,
816816
lu_byte tag = *t->getArrayTag(i);
817817
if (!tagisempty(tag)) { /* a non-empty entry? */
818818
TValue key, aux;
819-
setivalue(&key, l_castU2S(i) + 1); /* make the key */
819+
key.setInt(l_castU2S(i) + 1); /* make the key */
820820
farr2val(t, i, tag, &aux); /* copy value into 'aux' */
821821
insertkey(t, &key, &aux); /* insert entry into the hash part */
822822
}
@@ -1513,7 +1513,7 @@ void Table::setInt(lua_State* L, lua_Integer key, TValue* value) {
15131513
bool ok = rawfinishnodeset(getintfromhash(this, key), value);
15141514
if (!ok) {
15151515
TValue k;
1516-
setivalue(&k, key);
1516+
k.setInt(key);
15171517
luaH_newkey(L, this, &k, value);
15181518
}
15191519
}
@@ -1529,7 +1529,7 @@ void Table::finishSet(lua_State* L, const TValue* key, TValue* value, int hres)
15291529
lua_Number f = fltvalue(key);
15301530
lua_Integer k;
15311531
if (luaV_flttointeger(f, &k, F2Imod::F2Ieq)) {
1532-
setivalue(&aux, k); /* key is equal to an integer */
1532+
aux.setInt(k); /* key is equal to an integer */
15331533
key = &aux; /* insert it as an integer */
15341534
}
15351535
else if (l_unlikely(luai_numisnan(f)))

src/serialization/ldump.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ static void dumpString (DumpState *D, TString *ts) {
163163
dumpVector(D, s, size + 1); /* include ending '\0' */
164164
D->nstr++; /* one more saved string */
165165
setsvalue(D->L, &key, ts); /* the string is the key */
166-
setivalue(&value, l_castU2S(D->nstr)); /* its index is the value */
166+
value.setInt(l_castU2S(D->nstr)); /* its index is the value */
167167
luaH_set(D->L, D->h, &key, &value); /* h[ts] = nstr */
168168
/* integer value does not need barrier */
169169
}

src/serialization/lundump.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,10 +235,10 @@ static void loadConstants (LoadState *S, Proto *f) {
235235
setbtvalue(o);
236236
break;
237237
case LUA_VNUMFLT:
238-
setfltvalue(o, loadNumber(S));
238+
o->setFloat(loadNumber(S));
239239
break;
240240
case LUA_VNUMINT:
241-
setivalue(o, loadInteger(S));
241+
o->setInt(loadInteger(S));
242242
break;
243243
case LUA_VSHRSTR:
244244
case LUA_VLNGSTR: {

src/vm/lvm.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -603,12 +603,12 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
603603
int imm = InstructionView(i).sc();
604604
if (ttisinteger(v1)) {
605605
lua_Integer iv1 = ivalue(v1);
606-
pc++; setivalue(ra, iop(L, iv1, imm));
606+
pc++; ra->setInt(iop(L, iv1, imm));
607607
}
608608
else if (ttisfloat(v1)) {
609609
lua_Number nb = fltvalue(v1);
610610
lua_Number fimm = cast_num(imm);
611-
pc++; setfltvalue(ra, fop(L, nb, fimm));
611+
pc++; ra->setFloat(fop(L, nb, fimm));
612612
}
613613
};
614614

@@ -617,7 +617,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
617617
lua_Number n1, n2;
618618
if (tonumberns(v1, n1) && tonumberns(v2, n2)) {
619619
StkId ra = RA(i);
620-
pc++; setfltvalue(s2v(ra), fop(L, n1, n2));
620+
pc++; s2v(ra)->setFloat(fop(L, n1, n2));
621621
}
622622
};
623623

@@ -642,7 +642,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
642642
StkId ra = RA(i);
643643
lua_Integer i1 = ivalue(v1);
644644
lua_Integer i2 = ivalue(v2);
645-
pc++; setivalue(s2v(ra), iop(L, i1, i2));
645+
pc++; s2v(ra)->setInt(iop(L, i1, i2));
646646
}
647647
else {
648648
op_arithf_aux(v1, v2, fop, i);
@@ -672,7 +672,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
672672
lua_Integer i2 = ivalue(v2);
673673
if (tointegerns(v1, &i1)) {
674674
StkId ra = RA(i);
675-
pc++; setivalue(s2v(ra), op(i1, i2));
675+
pc++; s2v(ra)->setInt(op(i1, i2));
676676
}
677677
};
678678

@@ -683,7 +683,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
683683
lua_Integer i1, i2;
684684
if (tointegerns(v1, &i1) && tointegerns(v2, &i2)) {
685685
StkId ra = RA(i);
686-
pc++; setivalue(s2v(ra), op(i1, i2));
686+
pc++; s2v(ra)->setInt(op(i1, i2));
687687
}
688688
};
689689

@@ -768,13 +768,13 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
768768
vmcase(OP_LOADI) {
769769
StkId ra = RA(i);
770770
lua_Integer b = InstructionView(i).sbx();
771-
setivalue(s2v(ra), b);
771+
s2v(ra)->setInt(b);
772772
vmbreak;
773773
}
774774
vmcase(OP_LOADF) {
775775
StkId ra = RA(i);
776776
int b = InstructionView(i).sbx();
777-
setfltvalue(s2v(ra), cast_num(b));
777+
s2v(ra)->setFloat(cast_num(b));
778778
vmbreak;
779779
}
780780
vmcase(OP_LOADK) {
@@ -859,7 +859,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
859859
luaV_fastgeti(rb, c, s2v(ra), tag);
860860
if (tagisempty(tag)) {
861861
TValue key;
862-
setivalue(&key, c);
862+
key.setInt(c);
863863
Protect([&]() { luaV_finishget(L, rb, &key, ra, tag); });
864864
}
865865
vmbreak;
@@ -915,7 +915,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
915915
luaV_finishfastset(L, s2v(ra), rc);
916916
else {
917917
TValue key;
918-
setivalue(&key, b);
918+
key.setInt(b);
919919
Protect([&]() { luaV_finishset(L, s2v(ra), &key, rc, hres); });
920920
}
921921
vmbreak;
@@ -1018,7 +1018,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
10181018
int ic = InstructionView(i).sc();
10191019
lua_Integer ib;
10201020
if (tointegerns(rb, &ib)) {
1021-
pc++; setivalue(s2v(ra), luaV_shiftl(ic, ib));
1021+
pc++; s2v(ra)->setInt(luaV_shiftl(ic, ib));
10221022
}
10231023
vmbreak;
10241024
}
@@ -1028,7 +1028,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
10281028
int ic = InstructionView(i).sc();
10291029
lua_Integer ib;
10301030
if (tointegerns(rb, &ib)) {
1031-
pc++; setivalue(s2v(ra), luaV_shiftl(ib, -ic));
1031+
pc++; s2v(ra)->setInt(luaV_shiftl(ib, -ic));
10321032
}
10331033
vmbreak;
10341034
}
@@ -1118,10 +1118,10 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
11181118
lua_Number nb;
11191119
if (ttisinteger(rb)) {
11201120
lua_Integer ib = ivalue(rb);
1121-
setivalue(s2v(ra), intop(-, 0, ib));
1121+
s2v(ra)->setInt(intop(-, 0, ib));
11221122
}
11231123
else if (tonumberns(rb, nb)) {
1124-
setfltvalue(s2v(ra), luai_numunm(L, nb));
1124+
s2v(ra)->setFloat(luai_numunm(L, nb));
11251125
}
11261126
else
11271127
Protect([&]() { luaT_trybinTM(L, rb, rb, ra, TMS::TM_UNM); });
@@ -1132,7 +1132,7 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
11321132
TValue *rb = vRB(i);
11331133
lua_Integer ib;
11341134
if (tointegerns(rb, &ib)) {
1135-
setivalue(s2v(ra), intop(^, ~l_castS2U(0), ib));
1135+
s2v(ra)->setInt(intop(^, ~l_castS2U(0), ib));
11361136
}
11371137
else
11381138
Protect([&]() { luaT_trybinTM(L, rb, rb, ra, TMS::TM_BNOT); });
@@ -1368,9 +1368,9 @@ void luaV_execute (lua_State *L, CallInfo *ci) {
13681368
if (count > 0) { /* still more iterations? */
13691369
lua_Integer step = ivalue(s2v(ra + 1));
13701370
lua_Integer idx = ivalue(s2v(ra + 2)); /* control variable */
1371-
chgivalue(s2v(ra), l_castU2S(count - 1)); /* update counter */
1371+
s2v(ra)->changeInt(l_castU2S(count - 1)); /* update counter */
13721372
idx = intop(+, idx, step); /* add step to index */
1373-
chgivalue(s2v(ra + 2), idx); /* update control variable */
1373+
s2v(ra + 2)->changeInt(idx); /* update control variable */
13741374
pc -= InstructionView(i).bx(); /* jump back */
13751375
}
13761376
}

0 commit comments

Comments
 (0)