[前][次][番号順一覧][スレッド一覧]

ruby-changes:31979

From: tmm1 <ko1@a...>
Date: Sun, 8 Dec 2013 10:52:36 +0900 (JST)
Subject: [ruby-changes:31979] tmm1:r44058 (trunk): hash.c: revert r43870 and add alternative parser patch for literal keys

tmm1	2013-12-08 10:52:28 +0900 (Sun, 08 Dec 2013)

  New Revision: 44058

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=44058

  Log:
    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

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
    trunk/parse.y
    trunk/test/ruby/test_hash.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 44057)
+++ ChangeLog	(revision 44058)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Dec  8 10:45:05 2013  Aman Gupta <ruby@t...>
+
+	* 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@t...>
 
 	* parse.y (register_symid_str): use fstrings in symbol table
Index: parse.y
===================================================================
--- parse.y	(revision 44057)
+++ parse.y	(revision 44058)
@@ -4912,6 +4912,10 @@ assocs		: assoc https://github.com/ruby/ruby/blob/trunk/parse.y#L4912
 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);
Index: hash.c
===================================================================
--- hash.c	(revision 44057)
+++ hash.c	(revision 44058)
@@ -1288,9 +1288,7 @@ static int https://github.com/ruby/ruby/blob/trunk/hash.c#L1288
 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);
 }
Index: test/ruby/test_hash.rb
===================================================================
--- test/ruby/test_hash.rb	(revision 44057)
+++ test/ruby/test_hash.rb	(revision 44058)
@@ -209,10 +209,11 @@ class TestHash < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_hash.rb#L209
     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 # '=='

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]