summaryrefslogtreecommitdiff
path: root/compile.c
diff options
context:
space:
mode:
authorko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-28 14:04:53 +0000
committerko1 <ko1@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-02-28 14:04:53 +0000
commit4cf0918e8e3d8b06d84c3cd3e875c82edb8b87e6 (patch)
tree986d16e605fee63e700b7e28a72aa0b00894728c /compile.c
parent338ec3cee73f58091927d9282070efd0da0cca36 (diff)
* compile.c (iseq_compile_each): remove redundant trace(line)
instruction. for example, at the following script def m() p:xyzzy 1 2 end compiler ignores `1' because there is no effect. However, `trace(line)' instruction remains in bytecode. This modification removes such redundant trace(line) instruction. * test/ruby/test_iseq.rb: add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@39539 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'compile.c')
-rw-r--r--compile.c9
1 files changed, 9 insertions, 0 deletions
diff --git a/compile.c b/compile.c
index fc5229f..8441d97 100644
--- a/compile.c
+++ b/compile.c
@@ -3154,6 +3154,7 @@ static int
iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
{
enum node_type type;
+ LINK_ELEMENT *saved_last_element = 0;
if (node == 0) {
if (!poped) {
@@ -3170,6 +3171,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
if (node->flags & NODE_FL_NEWLINE) {
ADD_TRACE(ret, nd_line(node), RUBY_EVENT_LINE);
+ saved_last_element = ret->last;
}
switch (type) {
@@ -5295,6 +5297,13 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped)
return COMPILE_NG;
}
+ /* check & remove redundant trace(line) */
+ if (saved_last_element && ret /* ret can be 0 when error */ &&
+ ret->last == saved_last_element &&
+ ((INSN *)saved_last_element)->insn_id == BIN(trace)) {
+ POP_ELEMENT(ret);
+ }
+
debug_node_end();
return COMPILE_OK;
}