summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-01 13:17:51 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-10-01 13:17:51 +0000
commit1b94420174641d78b99c45074e8770a91efa2d2b (patch)
treeff2f09fc6e9638e2658c351966f8f52de954ae35 /compile.c
parent8c401de5d90f33d7afecb813737a1f2924a5f096 (diff)
compile.c: literal range
* compile.c (iseq_compile_each): move numeric literal range optimization from fixup_nodes() in parse.y. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56316 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c17
1 files changed, 16 insertions, 1 deletions
diff --git a/compile.c b/compile.c
index 674ae70068..e2aef08902 100644
--- a/compile.c
+++ b/compile.c
@@ -3873,6 +3873,12 @@ compile_named_capture_assign(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE *node)
ADD_LABEL(ret, end_label);
}
+static int
+number_literal_p(NODE *n)
+{
+ return (n && nd_type(n) == NODE_LIT && RB_INTEGER_TYPE_P(n->nd_lit));
+}
+
/**
compile each node
@@ -5923,7 +5929,16 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
}
case NODE_DOT2:
case NODE_DOT3:{
- VALUE flag = type == NODE_DOT2 ? INT2FIX(0) : INT2FIX(1);
+ int excl = type == NODE_DOT3;
+ VALUE flag = INT2FIX(excl);
+ NODE *b = node->nd_beg;
+ NODE *e = node->nd_end;
+ if (number_literal_p(b) && number_literal_p(e)) {
+ VALUE val = rb_range_new(b->nd_lit, e->nd_lit, excl);
+ iseq_add_mark_object_compile_time(iseq, val);
+ ADD_INSN1(ret, line, putobject, val);
+ break;
+ }
COMPILE(ret, "min", (NODE *) node->nd_beg);
COMPILE(ret, "max", (NODE *) node->nd_end);
if (poped) {