summaryrefslogtreecommitdiff
path: root/enum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-16 06:02:37 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-03-16 06:02:37 +0000
commita920c29c16c8ffa2afe3f4126d307ee0001d5bc8 (patch)
tree1f14fbcedd311ee764b48e6938f775e850a8795a /enum.c
parenta157c85a7f1e6e11399c682218a60ebcdd093686 (diff)
* enum.c (enum_first): remove duplication.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35059 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r--enum.c33
1 files changed, 3 insertions, 30 deletions
diff --git a/enum.c b/enum.c
index bec34e8..1be1dea 100644
--- a/enum.c
+++ b/enum.c
@@ -703,22 +703,7 @@ first_i(VALUE i, VALUE params, int argc, VALUE *argv)
return Qnil; /* not reached */
}
-static VALUE
-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;
-}
+static VALUE enum_take(VALUE obj, VALUE n);
/*
* call-seq:
@@ -740,21 +725,9 @@ static VALUE
enum_first(int argc, VALUE *argv, VALUE obj)
{
NODE *memo;
+ rb_check_arity(argc, 0, 1);
if (argc > 0) {
- VALUE ary = Qnil;
- 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;
+ return enum_take(obj, argv[0]);
}
else {
memo = NEW_MEMO(Qnil, 0, 0);