diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | hash.c | 4 | ||||
-rw-r--r-- | test/ruby/test_hash.rb | 6 |
3 files changed, 15 insertions, 1 deletions
@@ -1,3 +1,9 @@ +Wed Nov 27 14:24:55 2013 Aman Gupta <ruby@tmm1.net> + + * 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@tmm1.net> * gc.c: Rename rb_heap_t members: @@ -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 ] |