Skip to content

Commit

Permalink
* enum.c (enum_take): get rid of extraneous iteration.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nobu committed Aug 20, 2008
1 parent 6537009 commit 51e0bcb
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 2 deletions.
4 changes: 4 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
Wed Aug 20 22:24:48 2008 Nobuyoshi Nakada <[email protected]>

* enum.c (enum_take): get rid of extraneous iteration.

Wed Aug 20 20:32:49 2008 Tanaka Akira <[email protected]>

* io.c (rb_io_open_with_args): use rb_open_file instead of rb_io_open.
Expand Down
5 changes: 3 additions & 2 deletions enum.c
Original file line number Diff line number Diff line change
Expand Up @@ -1585,8 +1585,8 @@ enum_zip(int argc, VALUE *argv, VALUE obj)
static VALUE
take_i(VALUE i, VALUE *arg, int argc, VALUE *argv)
{
if (arg[1]-- == 0) rb_iter_break();
rb_ary_push(arg[0], enum_values_pack(argc, argv));
if (--arg[1] == 0) rb_iter_break();
return Qnil;
}

Expand All @@ -1611,8 +1611,9 @@ enum_take(VALUE obj, VALUE n)
rb_raise(rb_eArgError, "attempt to take negative size");
}

args[1] = len;
if (len == 0) return rb_ary_new2(0);
args[0] = rb_ary_new();
args[1] = len;
rb_block_call(obj, id_each, 0, 0, take_i, (VALUE)args);
return args[0];
}
Expand Down

0 comments on commit 51e0bcb

Please sign in to comment.