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

ruby-changes:33321

From: nobu <ko1@a...>
Date: Tue, 25 Mar 2014 00:28:35 +0900 (JST)
Subject: [ruby-changes:33321] nobu:r45400 (trunk): vm.c: extract core_hash_merge

nobu	2014-03-25 00:28:31 +0900 (Tue, 25 Mar 2014)

  New Revision: 45400

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

  Log:
    vm.c: extract core_hash_merge
    
    * vm.c (core_hash_merge): extract from m_core_hash_merge_ary and
      m_core_hash_merge_ptr.

  Modified files:
    trunk/vm.c
Index: vm.c
===================================================================
--- vm.c	(revision 45399)
+++ vm.c	(revision 45400)
@@ -2253,6 +2253,18 @@ m_core_set_postexe(VALUE self) https://github.com/ruby/ruby/blob/trunk/vm.c#L2253
 static VALUE m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary);
 
 static VALUE
+core_hash_merge(VALUE hash, long argc, const VALUE *argv)
+{
+    long i;
+
+    assert(argc % 2 == 0);
+    for (i=0; i<argc; i+=2) {
+	rb_hash_aset(hash, argv[i], argv[i+1]);
+    }
+    return hash;
+}
+
+static VALUE
 m_core_hash_from_ary(VALUE self, VALUE ary)
 {
     VALUE hash = rb_hash_new();
@@ -2267,25 +2279,16 @@ m_core_hash_from_ary(VALUE self, VALUE a https://github.com/ruby/ruby/blob/trunk/vm.c#L2279
 static VALUE
 m_core_hash_merge_ary(VALUE self, VALUE hash, VALUE ary)
 {
-    int i;
-
-    assert(RARRAY_LEN(ary) % 2 == 0);
-    for (i=0; i<RARRAY_LEN(ary); i+=2) {
-	rb_hash_aset(hash, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
-    }
-
+    core_hash_merge(hash, RARRAY_LEN(ary), RARRAY_CONST_PTR(ary));
     return hash;
 }
 
 static VALUE
 m_core_hash_merge_ptr(int argc, VALUE *argv, VALUE recv)
 {
-    int i;
     VALUE hash = argv[0];
 
-    for (i=1; i<argc; i+=2) {
-	rb_hash_aset(hash, argv[i], argv[i+1]);
-    }
+    core_hash_merge(hash, argc-1, argv+1);
 
     return hash;
 }

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

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