1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* insns.def: add new instruction opt_empty_p' for optimize empty?'

method.  Apply a patch proposed at [ruby-dev:46120]
  [ruby-trunk - Feature #6972] by Glass_saga (Masaki Matsushita).
* compile.c (iseq_specialized_instruction), vm.c, vm_insnhelper.h:
  ditto.
* id.c, template/id.h.tmpl: ditto.
* test/ruby/test_optimization.rb: test for this changes.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37036 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
ko1 2012-09-26 09:34:46 +00:00
parent 24793ac32d
commit 1bebb22ce1
8 changed files with 74 additions and 0 deletions

View file

@ -85,6 +85,14 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal 6, "string".length
end
def test_string_empty?
assert_equal true, "".empty?
assert_equal false, "string".empty?
assert_nil redefine_method('String', 'empty?') { "string".empty? }
assert_equal true, "".empty?
assert_equal false, "string".empty?
end
def test_string_plus
assert_equal "", "" + ""
assert_equal "x", "x" + ""
@ -116,11 +124,21 @@ class TestRubyOptimization < Test::Unit::TestCase
assert_equal 3, [1,2,3].length
end
def test_array_empty?
assert_equal true, [].empty?
assert_equal false, [1,2,3].empty?
end
def test_hash_length
assert_equal 0, {}.length
assert_equal 1, {1=>1}.length
end
def test_hash_empty?
assert_equal true, {}.empty?
assert_equal false, {1=>1}.empty?
end
class MyObj
def ==(other)
true