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

ruby-changes:29934

From: glass <ko1@a...>
Date: Mon, 15 Jul 2013 14:20:24 +0900 (JST)
Subject: [ruby-changes:29934] glass:r41986 (trunk): * struct.c (rb_struct_each_pair): use rb_yield_values(2, key, value)

glass	2013-07-15 14:20:11 +0900 (Mon, 15 Jul 2013)

  New Revision: 41986

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

  Log:
    * struct.c (rb_struct_each_pair): use rb_yield_values(2, key, value)
      instead of rb_yield(rb_assoc_new(key, value)) if rb_block_arity()
      is greater than 1.

  Modified files:
    trunk/ChangeLog
    trunk/struct.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41985)
+++ ChangeLog	(revision 41986)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul 15 14:13:02 2013  Masaki Matsushita  <glass.saga@g...>
+
+	* struct.c (rb_struct_each_pair): use rb_yield_values(2, key, value)
+	  instead of rb_yield(rb_assoc_new(key, value)) if rb_block_arity()
+	  is greater than 1.
+
 Mon Jul 15 13:46:26 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c: Add static assertions.
Index: struct.c
===================================================================
--- struct.c	(revision 41985)
+++ struct.c	(revision 41986)
@@ -524,10 +524,19 @@ rb_struct_each_pair(VALUE s) https://github.com/ruby/ruby/blob/trunk/struct.c#L524
 
     RETURN_SIZED_ENUMERATOR(s, 0, 0, struct_enum_size);
     members = rb_struct_members(s);
-    for (i=0; i<RSTRUCT_LEN(s); i++) {
-	VALUE key = rb_ary_entry(members, i);
-	VALUE value = RSTRUCT_GET(s, i);
-	rb_yield(rb_assoc_new(key, value));
+    if (rb_block_arity() > 1) {
+	for (i=0; i<RSTRUCT_LEN(s); i++) {
+	    VALUE key = rb_ary_entry(members, i);
+	    VALUE value = RSTRUCT_GET(s, i);
+	    rb_yield_values(2, key, value);
+	}
+    }
+    else {
+	for (i=0; i<RSTRUCT_LEN(s); i++) {
+	    VALUE key = rb_ary_entry(members, i);
+	    VALUE value = RSTRUCT_GET(s, i);
+	    rb_yield(rb_assoc_new(key, value));
+	}
     }
     return s;
 }

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

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