mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23622 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
6eaf79f39a
commit
967001d9da
2 changed files with 18 additions and 6 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
Tue Jun 2 17:32:40 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@mbf.nifty.com>
|
Tue Jun 2 13:27:21 2009 Kazuhiro NISHIYAMA <zn@mbf.nifty.com>
|
||||||
|
|
||||||
* test/ripper/test_filter.rb: add tests. see [ruby-dev:37856]
|
* test/ripper/test_filter.rb: add tests. see [ruby-dev:37856]
|
||||||
|
|
16
enum.c
16
enum.c
|
@ -617,14 +617,14 @@ first_i(VALUE i, VALUE *ary, int argc, VALUE *argv)
|
||||||
rb_iter_break();
|
rb_iter_break();
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
long n = NUM2LONG(ary[0]);
|
long n = ary[0];
|
||||||
|
|
||||||
|
rb_ary_push(ary[1], i);
|
||||||
|
n--;
|
||||||
if (n <= 0) {
|
if (n <= 0) {
|
||||||
rb_iter_break();
|
rb_iter_break();
|
||||||
}
|
}
|
||||||
rb_ary_push(ary[1], i);
|
ary[0] = n;
|
||||||
n--;
|
|
||||||
ary[0] = INT2NUM(n);
|
|
||||||
}
|
}
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
@ -649,9 +649,13 @@ enum_first(int argc, VALUE *argv, VALUE obj)
|
||||||
ary[0] = ary[1] = Qnil;
|
ary[0] = ary[1] = Qnil;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
long len;
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &n);
|
rb_scan_args(argc, argv, "01", &n);
|
||||||
ary[0] = n;
|
len = NUM2LONG(n);
|
||||||
ary[1] = rb_ary_new2(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);
|
rb_block_call(obj, id_each, 0, 0, first_i, (VALUE)ary);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue