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

ruby-changes:30941

From: glass <ko1@a...>
Date: Mon, 23 Sep 2013 12:17:46 +0900 (JST)
Subject: [ruby-changes:30941] glass:r43020 (trunk): * hash.c (env_each_pair): do not call rb_assoc_new() if

glass	2013-09-23 12:17:38 +0900 (Mon, 23 Sep 2013)

  New Revision: 43020

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

  Log:
    * hash.c (env_each_pair): do not call rb_assoc_new() if
      it isn't needed.

  Modified files:
    trunk/ChangeLog
    trunk/hash.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43019)
+++ ChangeLog	(revision 43020)
@@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Sep 23 12:11:26 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* hash.c (env_each_pair): do not call rb_assoc_new() if
+	  it isn't needed.
+
 Mon Sep 23 10:42:30 2013  Nobuyoshi Nakada  <nobu@r...>
 
 	* test/ruby/test_module.rb (TestModule#test_include_toplevel): test
Index: hash.c
===================================================================
--- hash.c	(revision 43019)
+++ hash.c	(revision 43020)
@@ -2901,8 +2901,15 @@ env_each_pair(VALUE ehash) https://github.com/ruby/ruby/blob/trunk/hash.c#L2901
     }
     FREE_ENVIRON(environ);
 
-    for (i=0; i<RARRAY_LEN(ary); i+=2) {
-	rb_yield(rb_assoc_new(RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1)));
+    if (rb_block_arity() > 1) {
+	for (i=0; i<RARRAY_LEN(ary); i+=2) {
+	    rb_yield_values(2, RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1));
+	}
+    }
+    else {
+	for (i=0; i<RARRAY_LEN(ary); i+=2) {
+	    rb_yield(rb_assoc_new(RARRAY_AREF(ary, i), RARRAY_AREF(ary, i+1)));
+	}
     }
     return ehash;
 }

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

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