From eb8f91866e0bd08a6eef9c9a2bc1318e06b4ee4d Mon Sep 17 00:00:00 2001 From: glass Date: Mon, 29 Jul 2013 12:39:21 +0000 Subject: * hash.c (rb_hash_assoc): performance improvement by replacing compare function in RHASH(hash)->ntbl->type temporarily like r42224. it falls back to rb_hash_foreach() if st_lookup() doesn't find the key. * test/ruby/test_hash.rb: add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@42237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'test/ruby/test_hash.rb') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 5694d2f01e..82eba0b352 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -879,6 +879,14 @@ class TestHash < Test::Unit::TestCase assert_equal([1.0,1], {1.0=>1}.assoc(1)) end + def test_assoc_compare_by_identity + h = {} + h.compare_by_identity + h["a"] = 1 + h["a"] = 2 + assert_equal(["a",1], h.assoc("a")) + end + def test_rassoc assert_equal([3,4], {1=>2, 3=>4, 5=>6}.rassoc(4)) assert_nil({1=>2, 3=>4, 5=>6}.rassoc(3)) -- cgit v1.2.3