ruby-changes:32900
From: nagachika <ko1@a...>
Date: Sun, 16 Feb 2014 00:43:08 +0900 (JST)
Subject: [ruby-changes:32900] nagachika:r44979 (ruby_2_0_0): merge revision(s) r42224, r42225, r42226, r42227, r42228, r42229, r42232: [Backport #8703]
nagachika 2014-02-16 00:43:02 +0900 (Sun, 16 Feb 2014) New Revision: 44979 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44979 Log: merge revision(s) r42224,r42225,r42226,r42227,r42228,r42229,r42232: [Backport #8703] * hash.c (rb_hash_assoc): performance improvement by replacing compare function in RHASH(hash)->ntbl->type temporarily. * hash.c (rb_hash_assoc): aggregate object can be initialized only with link time constants. * hash.c (rb_hash_initialize_copy): clear old table before copy new table. * hash.c (rb_hash_initialize_copy): copy st_table type even if empty. [ruby-core:56256] [Bug #8703] * hash.c (rb_hash_initialize_copy): copy st_table type even if empty. [ruby-core:56256] [Bug #8703] * hash.c (rb_hash_initialize_copy): clear old table before copy new table. * hash.c (rb_hash_assoc): aggregate object can be initialized only with link time constants. * hash.c (rb_hash_assoc): revert r42224. table->type->compare is called only if hashes are matched. * test/ruby/test_hash.rb: add a test to check using #== to compare. Modified directories: branches/ruby_2_0_0/ Modified files: branches/ruby_2_0_0/ChangeLog branches/ruby_2_0_0/hash.c branches/ruby_2_0_0/test/ruby/test_hash.rb branches/ruby_2_0_0/version.h Index: ruby_2_0_0/ChangeLog =================================================================== --- ruby_2_0_0/ChangeLog (revision 44978) +++ ruby_2_0_0/ChangeLog (revision 44979) @@ -1,3 +1,30 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/ChangeLog#L1 +Sun Feb 16 00:27:04 2014 Masaki Matsushita <glass.saga@g...> + + * hash.c (rb_hash_assoc): revert r42224. table->type->compare is + called only if hashes are matched. + + * test/ruby/test_hash.rb: add a test to check using #== to compare. + +Sun Feb 16 00:27:04 2014 Nobuyoshi Nakada <nobu@r...> + + * hash.c (rb_hash_initialize_copy): copy st_table type even if empty. + [ruby-core:56256] [Bug #8703] + +Sun Feb 16 00:27:04 2014 Nobuyoshi Nakada <nobu@r...> + + * hash.c (rb_hash_initialize_copy): clear old table before copy new + table. + +Sun Feb 16 00:27:04 2014 Nobuyoshi Nakada <nobu@r...> + + * hash.c (rb_hash_assoc): aggregate object can be initialized only + with link time constants. + +Sun Feb 16 00:27:04 2014 Masaki Matsushita <glass.saga@g...> + + * hash.c (rb_hash_assoc): performance improvement by replacing + compare function in RHASH(hash)->ntbl->type temporarily. + Sun Feb 16 00:01:16 2014 Tanaka Akira <akr@f...> * lib/resolv.rb: Ignore name servers which cause EAFNOSUPPORT on Index: ruby_2_0_0/hash.c =================================================================== --- ruby_2_0_0/hash.c (revision 44978) +++ ruby_2_0_0/hash.c (revision 44979) @@ -1223,14 +1223,22 @@ replace_i(VALUE key, VALUE val, VALUE ha https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/hash.c#L1223 static VALUE rb_hash_initialize_copy(VALUE hash, VALUE hash2) { + st_table *ntbl; + rb_hash_modify_check(hash); hash2 = to_hash(hash2); Check_Type(hash2, T_HASH); - if (!RHASH_EMPTY_P(hash2)) { + ntbl = RHASH(hash)->ntbl; + if (RHASH(hash2)->ntbl) { + if (ntbl) st_free_table(ntbl); RHASH(hash)->ntbl = st_copy(RHASH(hash2)->ntbl); - rb_hash_rehash(hash); + if (RHASH(hash)->ntbl->num_entries) + rb_hash_rehash(hash); + } + else if (ntbl) { + st_clear(ntbl); } if (FL_TEST(hash2, HASH_PROC_DEFAULT)) { Index: ruby_2_0_0/version.h =================================================================== --- ruby_2_0_0/version.h (revision 44978) +++ ruby_2_0_0/version.h (revision 44979) @@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/version.h#L1 #define RUBY_VERSION "2.0.0" #define RUBY_RELEASE_DATE "2014-02-16" -#define RUBY_PATCHLEVEL 413 +#define RUBY_PATCHLEVEL 414 #define RUBY_RELEASE_YEAR 2014 #define RUBY_RELEASE_MONTH 2 Index: ruby_2_0_0/test/ruby/test_hash.rb =================================================================== --- ruby_2_0_0/test/ruby/test_hash.rb (revision 44978) +++ ruby_2_0_0/test/ruby/test_hash.rb (revision 44979) @@ -102,6 +102,12 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_hash.rb#L102 assert_raises(TypeError) { h.dup } end + def test_clear_initialize_copy + h = @cls[1=>2] + h.instance_eval {initialize_copy({})} + assert_empty(h) + end + def test_dup_will_rehash set1 = @cls[] set2 = @cls[set1 => true] @@ -892,11 +898,12 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_hash.rb#L898 assert_equal([3,4], @cls[1=>2, 3=>4, 5=>6].assoc(3)) assert_nil(@cls[1=>2, 3=>4, 5=>6].assoc(4)) assert_equal([1.0,1], @cls[1.0=>1].assoc(1)) + assert_equal([1.0,1], @cls[1.0=>1].assoc(1)) end def test_rassoc assert_equal([3,4], @cls[1=>2, 3=>4, 5=>6].rassoc(4)) - assert_nil({1=>2, 3=>4, 5=>6}.rassoc(3)) + assert_nil(@cls[1=>2, 3=>4, 5=>6].rassoc(3)) end def test_flatten @@ -925,13 +932,17 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_0_0/test/ruby/test_hash.rb#L932 def test_compare_by_identity a = "foo" - assert(!{}.compare_by_identity?) - h = { a => "bar" } + assert_not_predicate(@cls[], :compare_by_identity?) + h = @cls[a => "bar"] assert(!h.compare_by_identity?) h.compare_by_identity assert(h.compare_by_identity?) #assert_equal("bar", h[a]) assert_nil(h["foo"]) + + bug8703 = '[ruby-core:56256] [Bug #8703] copied identhash' + h.clear + assert_predicate(h.dup, :compare_by_identity?, bug8703) end class ObjWithHash Property changes on: ruby_2_0_0 ___________________________________________________________________ Modified: svn:mergeinfo Merged /trunk:r42224-42229,42232 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/