1
0
mirror of https://github.com/lua/lua.git synced 2025-01-28 06:03:00 +08:00

small optimization (reorder of BinOpr enum to unify some cases

in switches)
This commit is contained in:
Roberto Ierusalimschy 2009-06-18 13:35:05 -03:00
parent 14115170bc
commit d7872dcf91
3 changed files with 23 additions and 22 deletions

27
lcode.c
View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.c,v 2.38 2009/06/15 13:52:08 roberto Exp roberto $
** $Id: lcode.c,v 2.39 2009/06/17 17:49:09 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -766,18 +766,19 @@ void luaK_posfix (FuncState *fs, BinOpr op, expdesc *e1, expdesc *e2) {
}
break;
}
case OPR_ADD: codearith(fs, OP_ADD, e1, e2); break;
case OPR_SUB: codearith(fs, OP_SUB, e1, e2); break;
case OPR_MUL: codearith(fs, OP_MUL, e1, e2); break;
case OPR_DIV: codearith(fs, OP_DIV, e1, e2); break;
case OPR_MOD: codearith(fs, OP_MOD, e1, e2); break;
case OPR_POW: codearith(fs, OP_POW, e1, e2); break;
case OPR_EQ: codecomp(fs, OP_EQ, 1, e1, e2); break;
case OPR_NE: codecomp(fs, OP_EQ, 0, e1, e2); break;
case OPR_LT: codecomp(fs, OP_LT, 1, e1, e2); break;
case OPR_LE: codecomp(fs, OP_LE, 1, e1, e2); break;
case OPR_GT: codecomp(fs, OP_LT, 0, e1, e2); break;
case OPR_GE: codecomp(fs, OP_LE, 0, e1, e2); break;
case OPR_ADD: case OPR_SUB: case OPR_MUL: case OPR_DIV:
case OPR_MOD: case OPR_POW: {
codearith(fs, op - OPR_ADD + OP_ADD, e1, e2);
break;
}
case OPR_EQ: case OPR_LT: case OPR_LE: {
codecomp(fs, op - OPR_EQ + OP_EQ, 1, e1, e2);
break;
}
case OPR_NE: case OPR_GT: case OPR_GE: {
codecomp(fs, op - OPR_NE + OP_EQ, 0, e1, e2);
break;
}
default: lua_assert(0);
}
}

View File

@ -1,5 +1,5 @@
/*
** $Id: lcode.h,v 1.49 2008/10/28 12:55:00 roberto Exp roberto $
** $Id: lcode.h,v 1.50 2009/06/10 16:52:03 roberto Exp roberto $
** Code generator for Lua
** See Copyright Notice in lua.h
*/
@ -21,13 +21,13 @@
/*
** grep "ORDER OPR" if you change these enums
** grep "ORDER OPR" if you change these enums (ORDER OP)
*/
typedef enum BinOpr {
OPR_ADD, OPR_SUB, OPR_MUL, OPR_DIV, OPR_MOD, OPR_POW,
OPR_CONCAT,
OPR_NE, OPR_EQ,
OPR_LT, OPR_LE, OPR_GT, OPR_GE,
OPR_EQ, OPR_LT, OPR_LE,
OPR_NE, OPR_GT, OPR_GE,
OPR_AND, OPR_OR,
OPR_NOBINOPR
} BinOpr;

View File

@ -1,5 +1,5 @@
/*
** $Id: lparser.c,v 2.62 2009/04/30 17:42:21 roberto Exp roberto $
** $Id: lparser.c,v 2.63 2009/06/10 16:52:03 roberto Exp roberto $
** Lua Parser
** See Copyright Notice in lua.h
*/
@ -813,10 +813,10 @@ static const struct {
lu_byte right; /* right priority */
} priority[] = { /* ORDER OPR */
{6, 6}, {6, 6}, {7, 7}, {7, 7}, {7, 7}, /* `+' `-' `*' `/' `%' */
{10, 9}, {5, 4}, /* power and concat (right associative) */
{3, 3}, {3, 3}, /* equality and inequality */
{3, 3}, {3, 3}, {3, 3}, {3, 3}, /* order */
{2, 2}, {1, 1} /* logical (and/or) */
{10, 9}, {5, 4}, /* ^, .. (right associative) */
{3, 3}, {3, 3}, {3, 3}, /* ==, <, <= */
{3, 3}, {3, 3}, {3, 3}, /* ~=, >, >= */
{2, 2}, {1, 1} /* and, or */
};
#define UNARY_PRIORITY 8 /* priority for unary operators */