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

ruby-changes:35796

From: nobu <ko1@a...>
Date: Sat, 11 Oct 2014 13:47:27 +0900 (JST)
Subject: [ruby-changes:35796] nobu:r47878 (trunk): vm.c: precedence of duplicated keys

nobu	2014-10-11 13:46:56 +0900 (Sat, 11 Oct 2014)

  New Revision: 47878

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

  Log:
    vm.c: precedence of duplicated keys
    
    * vm.c (kwmerge_i): override existing keys by new keys.
      [ruby-core:65368] [Bug #10315]

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_syntax.rb
    trunk/vm.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 47877)
+++ ChangeLog	(revision 47878)
@@ -1,4 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
-Sat Oct 11 13:46:53 2014  Nobuyoshi Nakada  <nobu@r...>
+Sat Oct 11 13:46:58 2014  Nobuyoshi Nakada  <nobu@r...>
+
+	* vm.c (kwmerge_i): override existing keys by new keys.
+	  [ruby-core:65368] [Bug #10315]
 
 	* parse.y (assocs): concatenate splatted literal hashes.  the
 	  former key has precedence even if duplicated literal keys
Index: vm.c
===================================================================
--- vm.c	(revision 47877)
+++ vm.c	(revision 47878)
@@ -2343,20 +2343,10 @@ m_core_hash_merge_ptr(int argc, VALUE *a https://github.com/ruby/ruby/blob/trunk/vm.c#L2343
 }
 
 static int
-kwmerge_ii(st_data_t *key, st_data_t *value, st_data_t arg, int existing)
-{
-    if (existing) return ST_STOP;
-    *value = arg;
-    return ST_CONTINUE;
-}
-
-static int
 kwmerge_i(VALUE key, VALUE value, VALUE hash)
 {
     if (!SYMBOL_P(key)) Check_Type(key, T_SYMBOL);
-    if (st_update(RHASH_TBL_RAW(hash), key, kwmerge_ii, (st_data_t)value) == 0) { /* !existing */
-	RB_OBJ_WRITTEN(hash, Qundef, value);
-    }
+    rb_hash_aset(hash, key, value);
     return ST_CONTINUE;
 }
 
Index: test/ruby/test_syntax.rb
===================================================================
--- test/ruby/test_syntax.rb	(revision 47877)
+++ test/ruby/test_syntax.rb	(revision 47878)
@@ -109,12 +109,12 @@ class TestSyntax < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_syntax.rb#L109
     def o.kw(k1: 1, k2: 2) [k1, k2] end
     h = {k1: 11, k2: 12}
     assert_equal([11, 12], o.kw(**h))
-    assert_equal([11, 22], o.kw(k2: 22, **h))
-    assert_equal([11, 12], o.kw(**h, **{k2: 22}))
-    assert_equal([11, 22], o.kw(**{k2: 22}, **h))
+    assert_equal([11, 12], o.kw(k2: 22, **h))
+    assert_equal([11, 22], o.kw(**h, **{k2: 22}))
+    assert_equal([11, 12], o.kw(**{k2: 22}, **h))
 
     bug10315 = '[ruby-core:65368] [Bug #10315]'
-    assert_equal([22, 2], o.kw(**{k1: 22}, **{k1: 23}), bug10315)
+    assert_equal([23, 2], o.kw(**{k1: 22}, **{k1: 23}), bug10315)
 
     h = {k3: 31}
     assert_raise(ArgumentError) {o.kw(**h)}

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

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