* enum.c (enum_first): remove duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
a157c85a7f
commit
a920c29c16
@ -1,3 +1,7 @@
|
|||||||
|
Fri Mar 16 15:02:35 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* enum.c (enum_first): remove duplication.
|
||||||
|
|
||||||
Fri Mar 16 14:43:18 2012 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
Fri Mar 16 14:43:18 2012 Yuki Sonoda (Yugui) <yugui@yugui.jp>
|
||||||
|
|
||||||
* load.c (ruby_init_ext): don't free the given pointer itself.
|
* load.c (ruby_init_ext): don't free the given pointer itself.
|
||||||
|
33
enum.c
33
enum.c
@ -703,22 +703,7 @@ first_i(VALUE i, VALUE params, int argc, VALUE *argv)
|
|||||||
return Qnil; /* not reached */
|
return Qnil; /* not reached */
|
||||||
}
|
}
|
||||||
|
|
||||||
static VALUE
|
static VALUE enum_take(VALUE obj, VALUE n);
|
||||||
first_ary_i(VALUE i, VALUE params, int argc, VALUE *argv)
|
|
||||||
{
|
|
||||||
NODE *memo = RNODE(params);
|
|
||||||
long n = memo->u3.cnt;
|
|
||||||
|
|
||||||
ENUM_WANT_SVALUE();
|
|
||||||
|
|
||||||
rb_ary_push(memo->u1.value, i);
|
|
||||||
n--;
|
|
||||||
if (n <= 0) {
|
|
||||||
rb_iter_break();
|
|
||||||
}
|
|
||||||
memo->u3.cnt = n;
|
|
||||||
return Qnil;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* call-seq:
|
* call-seq:
|
||||||
@ -740,21 +725,9 @@ static VALUE
|
|||||||
enum_first(int argc, VALUE *argv, VALUE obj)
|
enum_first(int argc, VALUE *argv, VALUE obj)
|
||||||
{
|
{
|
||||||
NODE *memo;
|
NODE *memo;
|
||||||
|
rb_check_arity(argc, 0, 1);
|
||||||
if (argc > 0) {
|
if (argc > 0) {
|
||||||
VALUE ary = Qnil;
|
return enum_take(obj, argv[0]);
|
||||||
VALUE n;
|
|
||||||
long len = 0;
|
|
||||||
|
|
||||||
rb_scan_args(argc, argv, "01", &n);
|
|
||||||
len = NUM2LONG(n);
|
|
||||||
if (len == 0) return rb_ary_new2(0);
|
|
||||||
if (len < 0) {
|
|
||||||
rb_raise(rb_eArgError, "negative length");
|
|
||||||
}
|
|
||||||
ary = rb_ary_new2(len);
|
|
||||||
memo = NEW_MEMO(ary, 0, len);
|
|
||||||
rb_block_call(obj, id_each, 0, 0, first_ary_i, (VALUE)memo);
|
|
||||||
return ary;
|
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
memo = NEW_MEMO(Qnil, 0, 0);
|
memo = NEW_MEMO(Qnil, 0, 0);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user