From 58f800a278b8b70463f4afdbb23a918d8ab441ff Mon Sep 17 00:00:00 2001 From: tmm1 Date: Fri, 10 Jan 2014 04:54:08 +0000 Subject: insns.def: add opt path for Hash#[] and Hash#[]= used with str literal keys * insns.def (opt_aref_with): new instruction to optimize Hash#[], removing any allocation overhead when used with a string literal key. Patch by normalperson (Eric Wong). [ruby-core:59640] [Bug #9382] * insns.def (opt_aset_with): new instruction to optimize Hash#[]= * compile.c (iseq_compile_each): compiler shortcuts for new instructions * hash.c (static VALUE rb_hash_compare_by_id_p): fix documentation for Hash#compare_by_identity to reflect frozen string sharing * test/ruby/test_hash.rb (class TestHash): test for new behavior git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44551 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) (limited to 'test/ruby/test_hash.rb') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 3861fde0a4..c39cd23d54 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -209,6 +209,20 @@ class TestHash < Test::Unit::TestCase assert_equal(256, h[z]) end + def test_AREF_fstring_key + h = {"abc" => 1} + before = GC.stat(:total_allocated_object) + 5.times{ h["abc"] } + assert_equal before, GC.stat(:total_allocated_object) + end + + def test_ASET_fstring_key + a, b = {}, {} + assert_equal 1, a["abc"] = 1 + assert_equal 1, b["abc"] = 1 + assert_same a.keys[0], b.keys[0] + end + def test_NEWHASH_fstring_key a = {"ABC" => :t} b = {"ABC" => :t} @@ -946,7 +960,7 @@ class TestHash < Test::Unit::TestCase h = @cls[] h.compare_by_identity h["a"] = 1 - h["a"] = 2 + h["a".dup] = 2 assert_equal(["a",1], h.assoc("a")) end -- cgit v1.2.3