diff --git a/ChangeLog b/ChangeLog index d1cf9a00dc..7765672839 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +Sun Dec 8 10:45:05 2013 Aman Gupta + + * hash.c (hash_aset_str): revert r43870 due to performance issue + [Bug #9188] [ruby-core:58730] + * parse.y (assoc): convert literal string hash keys to fstrings + * test/ruby/test_hash.rb (class TestHash): expand test + Sun Dec 8 10:22:38 2013 Aman Gupta * parse.y (register_symid_str): use fstrings in symbol table diff --git a/hash.c b/hash.c index a52e02ff67..1321b83191 100644 --- a/hash.c +++ b/hash.c @@ -1288,9 +1288,7 @@ static int hash_aset_str(st_data_t *key, st_data_t *val, struct update_arg *arg, int existing) { if (!existing) { - VALUE str = (VALUE)*key; - if (!OBJ_FROZEN(str)) - *key = rb_fstring(str); + *key = rb_str_new_frozen(*key); } return hash_aset(key, val, arg, existing); } diff --git a/parse.y b/parse.y index 2a0c5c64f7..d04cf45612 100644 --- a/parse.y +++ b/parse.y @@ -4912,6 +4912,10 @@ assocs : assoc assoc : arg_value tASSOC arg_value { /*%%%*/ + if (nd_type($1) == NODE_STR) { + nd_set_type($1, NODE_LIT); + $1->nd_lit = rb_fstring($1->nd_lit); + } $$ = list_append(NEW_LIST($1), $3); /*% $$ = dispatch2(assoc_new, $1, $3); diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index 6aaba469db..4244b86b56 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -209,10 +209,11 @@ class TestHash < Test::Unit::TestCase assert_equal(256, h[z]) end - def test_ASET_string + def test_NEWHASH_fstring_key a = {"ABC" => :t} b = {"ABC" => :t} assert_same a.keys[0], b.keys[0] + assert_same "ABC".freeze, a.keys[0] end def test_EQUAL # '=='