aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_iseq.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-23 02:58:22 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-10-23 02:58:22 +0000
commitdf56684bb6f595e5c2bd7cc6eec0c4026534640f (patch)
tree5694e105b2b199b5830807dd0aca43c1461bdeba /test/ruby/test_iseq.rb
parentacbe98da6057aa790fb89ee52f7669ea290b6979 (diff)
downloadruby-df56684bb6f595e5c2bd7cc6eec0c4026534640f.tar.gz
compile.c: optimize method chain
* compile.c (iseq_peephole_optimize): optimize lengthy safe navigation method chain. [Feature #11537] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@52237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_iseq.rb')
-rw-r--r--test/ruby/test_iseq.rb23
1 files changed, 17 insertions, 6 deletions
diff --git a/test/ruby/test_iseq.rb b/test/ruby/test_iseq.rb
index ff47760173..f87a8a0361 100644
--- a/test/ruby/test_iseq.rb
+++ b/test/ruby/test_iseq.rb
@@ -8,8 +8,12 @@ class TestISeq < Test::Unit::TestCase
assert_normal_exit('p RubyVM::InstructionSequence.compile("1", "mac", "", 0).to_a', bug5894)
end
+ def compile(src, line = nil, opt = nil)
+ RubyVM::InstructionSequence.new(src, __FILE__, __FILE__, line, opt)
+ end
+
def lines src
- body = RubyVM::InstructionSequence.new(src).to_a[13]
+ body = compile(src).to_a[13]
body.find_all{|e| e.kind_of? Fixnum}
end
@@ -52,7 +56,7 @@ class TestISeq < Test::Unit::TestCase
end if defined?(RubyVM::InstructionSequence.load)
def test_loaded_cdhash_mark
- iseq = RubyVM::InstructionSequence.compile(<<-'end;', __FILE__, __FILE__, __LINE__+1)
+ iseq = compile(<<-'end;', __LINE__+1)
def bug(kw)
case kw
when "false" then false
@@ -73,11 +77,11 @@ class TestISeq < Test::Unit::TestCase
def test_disasm_encoding
src = "\u{3042} = 1; \u{3042}; \u{3043}"
- asm = RubyVM::InstructionSequence.compile(src).disasm
+ asm = compile(src).disasm
assert_equal(src.encoding, asm.encoding)
assert_predicate(asm, :valid_encoding?)
src.encode!(Encoding::Shift_JIS)
- asm = RubyVM::InstructionSequence.compile(src).disasm
+ asm = compile(src).disasm
assert_equal(src.encoding, asm.encoding)
assert_predicate(asm, :valid_encoding?)
end
@@ -147,7 +151,7 @@ class TestISeq < Test::Unit::TestCase
def test_disable_opt
src = "a['foo'] = a['bar']; 'a'.freeze"
- _,_,_,_,_,_,_,_,_,_,_,_,_,body= RubyVM::InstructionSequence.compile(src, __FILE__, __FILE__, __LINE__, false).to_a
+ body= compile(src, __LINE__, false).to_a[13]
body.each{|insn|
next unless Array === insn
op = insn.first
@@ -168,11 +172,18 @@ class TestISeq < Test::Unit::TestCase
code = <<-'EOS'
['foo', 'foo', "#{$f}foo", "#{'foo'}"]
EOS
- s1, s2, s3, s4 = RubyVM::InstructionSequence.compile(code, __FILE__, __FILE__, line, {frozen_string_literal: true}).eval
+ s1, s2, s3, s4 = compile(code, line, {frozen_string_literal: true}).eval
assert_predicate(s1, :frozen?)
assert_predicate(s2, :frozen?)
assert_not_predicate(s3, :frozen?)
assert_predicate(s4, :frozen?)
assert_same(s1, s2)
end
+
+ def test_safe_call_chain
+ src = "a.?a.?a.?a.?a.?a"
+ body = compile(src, __LINE__, {peephole_optimization: true}).to_a[13]
+ labels = body.select {|op, arg| op == :branchnil}.map {|op, arg| arg}
+ assert_equal(1, labels.uniq.size)
+ end
end