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

ruby-changes:11960

From: matz <ko1@a...>
Date: Wed, 3 Jun 2009 09:08:54 +0900 (JST)
Subject: [ruby-changes:11960] Ruby:r23624 (ruby_1_8): * enum.c (first_i): Enumerator#first should consume only what is

matz	2009-06-03 09:08:43 +0900 (Wed, 03 Jun 2009)

  New Revision: 23624

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

  Log:
    * enum.c (first_i): Enumerator#first should consume only what is
      needed.   a patch from Marc-Andre Lafortune.  [ruby-core:23661]
    * enum.c (take_i): ditto.
    
    * enum.c (enum_first): call to_int once for an argument.  a patch
      from Marc-Andre Lafortune.

  Modified files:
    branches/ruby_1_8/ChangeLog
    branches/ruby_1_8/enum.c

Index: ruby_1_8/ChangeLog
===================================================================
--- ruby_1_8/ChangeLog	(revision 23623)
+++ ruby_1_8/ChangeLog	(revision 23624)
@@ -1,3 +1,13 @@
+Wed Jun  3 06:12:26 2009  Yukihiro Matsumoto  <matz@r...>
+
+	* enum.c (first_i): Enumerator#first should consume only what is
+	  needed.   a patch from Marc-Andre Lafortune.  [ruby-core:23661]
+
+	* enum.c (take_i): ditto.
+
+	* enum.c (enum_first): call to_int once for an argument.  a patch
+	  from Marc-Andre Lafortune.
+
 Mon Jun  1 20:45:48 2009  NAKAMURA Usaku  <usa@r...>
 
 	* lib/mkmf.rb (create_makefile): should set srcs in all paths.
Index: ruby_1_8/enum.c
===================================================================
--- ruby_1_8/enum.c	(revision 23623)
+++ ruby_1_8/enum.c	(revision 23624)
@@ -667,11 +667,11 @@
     else {
 	long n = NUM2LONG(ary[0]);
 
+	rb_ary_push(ary[1], i);
+	n--;
 	if (n <= 0) {
 	    rb_iter_break();
 	}
-	rb_ary_push(ary[1], i);
-	n--;
 	ary[0] = INT2NUM(n);
     }
     return Qnil;
@@ -700,9 +700,12 @@
 	ary[0] = ary[1] = Qnil;
     }
     else {
+	long len;
 	rb_scan_args(argc, argv, "01", &n);
-	ary[0] = n;
-	ary[1] = rb_ary_new2(NUM2LONG(n));
+	len = NUM2LONG(n);
+	if (len == 0) return rb_ary_new2(0);
+	ary[0] = INT2NUM(len);
+	ary[1] = rb_ary_new2(len);
     }
     rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
 
@@ -1609,8 +1612,8 @@
     VALUE i;
     VALUE *arg;
 {
-    if (arg[1]-- == 0) rb_iter_break();
     rb_ary_push(arg[0], i);
+    if (--arg[1] == 0) rb_iter_break();
     return Qnil;
 }
 
@@ -1637,6 +1640,7 @@
 	rb_raise(rb_eArgError, "attempt to take negative size");
     }
 
+    if (len == 0) return rb_ary_new2(0);
     args[1] = len;
     args[0] = rb_ary_new();
     rb_block_call(obj, id_each, 0, 0, take_i, (VALUE)args);

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

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