From 779ae78995977305aa5aec9cb5b562dcf54c22e7 Mon Sep 17 00:00:00 2001 From: tmm1 Date: Sun, 8 Dec 2013 01:52:28 +0000 Subject: [PATCH] hash.c: revert r43870 and add alternative parser patch for literal keys * 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 git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44058 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 7 +++++++ hash.c | 4 +--- parse.y | 4 ++++ test/ruby/test_hash.rb | 3 ++- 4 files changed, 14 insertions(+), 4 deletions(-) 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 # '=='