From 0c3b3e9237e8fae4bdfd9e577b1f6275918e1abb Mon Sep 17 00:00:00 2001 From: tmm1 Date: Wed, 27 Nov 2013 05:28:55 +0000 Subject: * 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43870 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ hash.c | 4 +++- test/ruby/test_hash.rb | 6 ++++++ 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/ChangeLog b/ChangeLog index 5806882d17..84da1f7b12 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Wed Nov 27 14:24:55 2013 Aman Gupta + + * 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 * gc.c: Rename rb_heap_t members: diff --git a/hash.c b/hash.c index 9944b5f4b1..670e7adc12 100644 --- a/hash.c +++ b/hash.c @@ -1262,7 +1262,9 @@ static int 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); } diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 5f72dec5f4..49b74c7257 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -209,6 +209,12 @@ class TestHash < Test::Unit::TestCase 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 ] -- cgit v1.2.3