ruby-changes:11958
From: matz <ko1@a...>
Date: Wed, 3 Jun 2009 09:02:30 +0900 (JST)
Subject: [ruby-changes:11958] Ruby:r23622 (trunk): * enum.c (first_i): Enumerator#first should consume only what is
matz 2009-06-03 09:02:14 +0900 (Wed, 03 Jun 2009) New Revision: 23622 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23622 Log: * enum.c (first_i): Enumerator#first should consume only what is needed. a patch from Marc-Andre Lafortune. [ruby-core:23661] * enum.c (enum_first): call to_int once for an argument. based on a patch from Marc-Andre Lafortune. Modified files: trunk/ChangeLog trunk/enum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 23621) +++ ChangeLog (revision 23622) @@ -1,3 +1,11 @@ +Tue Jun 2 17:32:40 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 (enum_first): call to_int once for an argument. based on + a patch from Marc-Andre Lafortune. + Tue Jun 2 13:27:21 2009 Kazuhiro NISHIYAMA <zn@m...> * test/ripper/test_filter.rb: add tests. see [ruby-dev:37856] Index: enum.c =================================================================== --- enum.c (revision 23621) +++ enum.c (revision 23622) @@ -617,14 +617,14 @@ rb_iter_break(); } else { - long n = NUM2LONG(ary[0]); + long n = 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); + ary[0] = n; } return Qnil; } @@ -649,9 +649,13 @@ 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] = len; + ary[1] = rb_ary_new2(len); } rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/