Skip to content

Commit

Permalink
optimize if statement with constant condition
Browse files Browse the repository at this point in the history
  • Loading branch information
matz committed Oct 1, 2015
1 parent cb76ed8 commit 0a94c69
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions mrbgems/mruby-compiler/core/codegen.c
Expand Up @@ -1330,6 +1330,17 @@ codegen(codegen_scope *s, node *tree, int val)
int pos1, pos2;
node *e = tree->cdr->cdr->car;

switch ((intptr_t)tree->car->car) {
case NODE_TRUE:
case NODE_INT:
case NODE_STR:
codegen(s, tree->cdr->car, val);
return;
case NODE_FALSE:
case NODE_NIL:
codegen(s, e, val);
return;
}
codegen(s, tree->car, VAL);
pop();
pos1 = genop_peep(s, MKOP_AsBx(OP_JMPNOT, cursp(), 0), NOVAL);
Expand Down

0 comments on commit 0a94c69

Please sign in to comment.