[前][次][番号順一覧][スレッド一覧]

ruby-changes:30176

From: nobu <ko1@a...>
Date: Mon, 29 Jul 2013 16:51:34 +0900 (JST)
Subject: [ruby-changes:30176] nobu:r42228 (trunk): ChangeLog: commit miss

nobu	2013-07-29 16:51:23 +0900 (Mon, 29 Jul 2013)

  New Revision: 42228

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=42228

  Log:
    ChangeLog: commit miss

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 42227)
+++ ChangeLog	(revision 42228)
@@ -1,18 +1,3 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Mon Jul 29 16:48:38 2013  Nobuyoshi Nakada  <nobu@r...>
-
-	* hash.c (rb_hash_initialize_copy): copy st_table type even if empty.
-	  [ruby-core:56256] [Bug #8703]
-
-Mon Jul 29 16:34:29 2013  Nobuyoshi Nakada  <nobu@r...>
-
-	* hash.c (rb_hash_initialize_copy): clear old table before copy new
-	  table.
-
-Mon Jul 29 16:34:09 2013  Nobuyoshi Nakada  <nobu@r...>
-
-	* hash.c (rb_hash_assoc): aggregate object can be initialized only
-	  with link time constants.
-
 Mon Jul 29 14:54:44 2013  Masaki Matsushita  <glass.saga@g...>
 
 	* hash.c (rb_hash_assoc): performance improvement by replacing
Index: hash.c
===================================================================
--- hash.c	(revision 42227)
+++ hash.c	(revision 42228)
@@ -1306,14 +1306,22 @@ replace_i(VALUE key, VALUE val, VALUE ha https://github.com/ruby/ruby/blob/trunk/hash.c#L1306
 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)) {
@@ -2167,11 +2175,10 @@ rb_hash_assoc(VALUE hash, VALUE key) https://github.com/ruby/ruby/blob/trunk/hash.c#L2175
     struct lookup2_arg arg;
     struct reset_hash_type_arg ensure_arg;
     const struct st_hash_type *orighash = table->type;
-    const struct st_hash_type assochash = {
-	assoc_cmp,
-	orighash->hash,
-    };
+    struct st_hash_type assochash;
 
+    assochash.compare = assoc_cmp;
+    assochash.hash = orighash->hash;
     table->type = &assochash;
     arg.hash = hash;
     arg.key = key;
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 42227)
+++ test/ruby/test_hash.rb	(revision 42228)
@@ -102,6 +102,12 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/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 = { }
     set2 = { set1 => true}
@@ -912,13 +918,17 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L918
 
   def test_compare_by_identity
     a = "foo"
-    assert_not_predicate({}, :compare_by_identity?)
-    h = { a => "bar" }
+    assert_not_predicate(@cls[], :compare_by_identity?)
+    h = @cls[a => "bar"]
     assert_not_predicate(h, :compare_by_identity?)
     h.compare_by_identity
     assert_predicate(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

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]