Skip to content

Commit

Permalink
Avoid needless dereferencing
Browse files Browse the repository at this point in the history
  • Loading branch information
Sainan committed Jul 16, 2023
1 parent 64350ed commit 02245a7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
12 changes: 6 additions & 6 deletions src/lcode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1132,9 +1132,9 @@ static int jumponcond (FuncState *fs, expdesc *e, int cond) {
}


LUAI_FUNC bool luaK_isalwaytrue (FuncState *fs, expdesc *e) {
LUAI_FUNC bool luaK_isalwaytrue (LexState *ls, expdesc *e) {
if (e->k == VCONST) {
Vardesc *vd = &fs->ls->dyd->actvar.arr[e->u.info];
Vardesc *vd = &ls->dyd->actvar.arr[e->u.info];
lua_assert(vd->kind == RDKCTC);
if (ttisnumber(&vd->k) || ttisstring(&vd->k)) {
return true;
Expand All @@ -1148,9 +1148,9 @@ LUAI_FUNC bool luaK_isalwaytrue (FuncState *fs, expdesc *e) {
}


LUAI_FUNC bool luaK_isalwayfalse (FuncState *fs, expdesc *e) {
LUAI_FUNC bool luaK_isalwayfalse (LexState *ls, expdesc *e) {
if (e->k == VCONST) {
Vardesc *vd = &fs->ls->dyd->actvar.arr[e->u.info];
Vardesc *vd = &ls->dyd->actvar.arr[e->u.info];
lua_assert(vd->kind == RDKCTC);
if (ttisnil(&vd->k)) {
return true;
Expand All @@ -1170,7 +1170,7 @@ LUAI_FUNC bool luaK_isalwayfalse (FuncState *fs, expdesc *e) {
void luaK_goiftrue (FuncState *fs, expdesc *e) {
int pc; /* pc of new jump */
luaK_dischargevars(fs, e);
if (luaK_isalwaytrue(fs, e)) {
if (luaK_isalwaytrue(fs->ls, e)) {
pc = NO_JUMP; /* always true; do nothing */
}
else switch (e->k) {
Expand All @@ -1196,7 +1196,7 @@ void luaK_goiftrue (FuncState *fs, expdesc *e) {
void luaK_goiffalse (FuncState *fs, expdesc *e) {
int pc; /* pc of new jump */
luaK_dischargevars(fs, e);
if (luaK_isalwayfalse(fs, e)) {
if (luaK_isalwayfalse(fs->ls, e)) {
pc = NO_JUMP; /* always false; do nothing */
}
else switch (e->k) {
Expand Down
4 changes: 2 additions & 2 deletions src/lcode.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ LUAI_FUNC void luaK_exp2val (FuncState *fs, expdesc *e);
LUAI_FUNC int luaK_exp2RK (FuncState *fs, expdesc *e);
LUAI_FUNC void luaK_self (FuncState *fs, expdesc *e, expdesc *key);
LUAI_FUNC void luaK_indexed (FuncState *fs, expdesc *t, expdesc *k);
LUAI_FUNC bool luaK_isalwaytrue (FuncState *fs, expdesc *e);
LUAI_FUNC bool luaK_isalwayfalse (FuncState *fs, expdesc *e);
LUAI_FUNC bool luaK_isalwaytrue (LexState *ls, expdesc *e);
LUAI_FUNC bool luaK_isalwayfalse (LexState *ls, expdesc *e);
LUAI_FUNC void luaK_goifnil (FuncState *fs, expdesc *e);
LUAI_FUNC void luaK_goiftrue (FuncState *fs, expdesc *e);
LUAI_FUNC void luaK_goiffalse (FuncState *fs, expdesc *e);
Expand Down
6 changes: 3 additions & 3 deletions src/lparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3698,7 +3698,7 @@ static void test_then_block (LexState *ls, int *escapelist, TypeHint *prop) {
int jf; /* instruction to skip 'then' code (if condition is false) */
luaX_next(ls); /* skip IF or ELSEIF */
expr(ls, &v); /* read condition */
if (luaK_isalwayfalse(fs, &v))
if (luaK_isalwayfalse(ls, &v))
throw_warn(ls, "unreachable code", "this condition will never be truthy.", WT_UNREACHABLE_CODE);
checknext(ls, TK_THEN);
if (ls->t.token == TK_BREAK && luaX_lookahead(ls) != TK_INT) { /* 'if x then break' and not 'if x then break int' ? */
Expand Down Expand Up @@ -3747,9 +3747,9 @@ static void ifstat (LexState *ls, int line, TypeHint *prop = nullptr) {
static void constexprifstat (LexState *ls, int line, TypeHint *prop = nullptr) {
expdesc c;
expr(ls, &c);
const bool disposition = luaK_isalwaytrue(ls->fs, &c);
const bool disposition = luaK_isalwaytrue(ls, &c);
if (disposition == false) {
if (!luaK_isalwayfalse(ls->fs, &c)) {
if (!luaK_isalwayfalse(ls, &c)) {
luaX_syntaxerror(ls, "Compile-time 'if' must have a condition that can be evaluated at compile-time");
}
}
Expand Down

0 comments on commit 02245a7

Please sign in to comment.