Skip to content

Commit d7872dc

Browse files
committed
small optimization (reorder of BinOpr enum to unify some cases
in switches)
1 parent 1411517 commit d7872dc

3 files changed

Lines changed: 23 additions & 22 deletions

File tree

lcode.c

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.c,v 2.38 2009/06/15 13:52:08 roberto Exp roberto $
2+
** $Id: lcode.c,v 2.39 2009/06/17 17:49:09 roberto Exp roberto $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -766,18 +766,19 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
766766
}
767767
break;
768768
}
769-
case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
770-
case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
771-
case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
772-
case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
773-
case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
774-
case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
775-
case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
776-
case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
777-
case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
778-
case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
779-
case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
780-
case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
769+
case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
770+
case OPR_MOD: case OPR_POW: {
771+
codearith(fs, op - OPR_ADD + OP_ADD, e1, e2);
772+
break;
773+
}
774+
case OPR_EQ: case OPR_LT: case OPR_LE: {
775+
codecomp(fs, op - OPR_EQ + OP_EQ, 1, e1, e2);
776+
break;
777+
}
778+
case OPR_NE: case OPR_GT: case OPR_GE: {
779+
codecomp(fs, op - OPR_NE + OP_EQ, 0, e1, e2);
780+
break;
781+
}
781782
default: lua_assert(0);
782783
}
783784
}

lcode.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 roberto Exp roberto $
2+
** $Id: lcode.h,v 1.50 2009/06/10 16:52:03 roberto Exp roberto $
33
** Code generator for Lua
44
** See Copyright Notice in lua.h
55
*/
@@ -21,13 +21,13 @@
2121

2222

2323
/*
24-
** grep "ORDER OPR" if you change these enums
24+
** grep "ORDER OPR" if you change these enums (ORDER OP)
2525
*/
2626
typedef enum BinOpr {
2727
OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
2828
OPR_CONCAT,
29-
OPR_NE, OPR_EQ,
30-
OPR_LT, OPR_LE, OPR_GT, OPR_GE,
29+
OPR_EQ, OPR_LT, OPR_LE,
30+
OPR_NE, OPR_GT, OPR_GE,
3131
OPR_AND, OPR_OR,
3232
OPR_NOBINOPR
3333
} BinOpr;

lparser.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 roberto Exp roberto $
2+
** $Id: lparser.c,v 2.63 2009/06/10 16:52:03 roberto Exp roberto $
33
** Lua Parser
44
** See Copyright Notice in lua.h
55
*/
@@ -813,10 +813,10 @@ static const struct {
813813
lu_byte right; /* right priority */
814814
} priority[] = { /* ORDER OPR */
815815
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
816-
{10, 9}, {5, 4}, /* power and concat (right associative) */
817-
{3, 3}, {3, 3}, /* equality and inequality */
818-
{3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
819-
{2, 2}, {1, 1} /* logical (and/or) */
816+
{10, 9}, {5, 4}, /* ^, .. (right associative) */
817+
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
818+
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
819+
{2, 2}, {1, 1} /* and, or */
820820
};
821821

822822
#define UNARY_PRIORITY 8 /* priority for unary operators */

0 commit comments

Comments
 (0)