mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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
This commit is contained in:
parent
98a74d4dd5
commit
779ae78995
4 changed files with 14 additions and 4 deletions
|
@ -1,3 +1,10 @@
|
|||
Sun Dec 8 10:45:05 2013 Aman Gupta <ruby@tmm1.net>
|
||||
|
||||
* 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 <ruby@tmm1.net>
|
||||
|
||||
* parse.y (register_symid_str): use fstrings in symbol table
|
||||
|
|
4
hash.c
4
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);
|
||||
}
|
||||
|
|
4
parse.y
4
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);
|
||||
|
|
|
@ -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 # '=='
|
||||
|
|
Loading…
Reference in a new issue