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

ruby-changes:31791

From: tmm1 <ko1@a...>
Date: Wed, 27 Nov 2013 14:29:06 +0900 (JST)
Subject: [ruby-changes:31791] tmm1:r43870 (trunk): * hash.c (hash_aset_str): Use rb_fstring() to de-duplicate hash string

tmm1	2013-11-27 14:28:55 +0900 (Wed, 27 Nov 2013)

  New Revision: 43870

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

  Log:
    * hash.c (hash_aset_str): Use rb_fstring() to de-duplicate hash string
      keys. Patch by Eric Wong. [Bug #8998] [ruby-core:57727]
    * test/ruby/test_hash.rb (class TestHash): test for above.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/test/ruby/test_hash.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43869)
+++ ChangeLog	(revision 43870)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 27 14:24:55 2013  Aman Gupta <ruby@t...>
+
+	* hash.c (hash_aset_str): Use rb_fstring() to de-duplicate hash string
+	  keys. Patch by Eric Wong. [Bug #8998] [ruby-core:57727]
+	* test/ruby/test_hash.rb (class TestHash): test for above.
+
 Wed Nov 27 10:39:39 2013  Aman Gupta <ruby@t...>
 
 	* gc.c: Rename rb_heap_t members:
Index: hash.c
===================================================================
--- hash.c	(revision 43869)
+++ hash.c	(revision 43870)
@@ -1262,7 +1262,9 @@ static int https://github.com/ruby/ruby/blob/trunk/hash.c#L1262
 hash_aset_str(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing)
 {
     if (!existing) {
-	*key = rb_str_new_frozen((VALUE)*key);
+	VALUE str = (VALUE)*key;
+	if (!OBJ_FROZEN(str))
+	    *key = rb_fstring((VALUE)*key);
     }
     return hash_aset(key, val, arg, existing);
 }
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 43869)
+++ test/ruby/test_hash.rb	(revision 43870)
@@ -209,6 +209,12 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L209
     assert_equal(256,     h[z])
   end
 
+  def test_ASET_string
+    a = {"ABC" => :t}
+    b = {"ABC" => :t}
+    assert_equal a.keys[0].object_id, b.keys[0].object_id
+  end
+
   def test_EQUAL # '=='
     h1 = @cls[ "a" => 1, "c" => 2 ]
     h2 = @cls[ "a" => 1, "c" => 2, 7 => 35 ]

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

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