diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-20 13:24:51 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-20 13:24:51 +0000 |
commit | c032557a66a6d37670850a8352768de8e4199e9f (patch) | |
tree | 813a0b42faf970b65e579fd7a54a8957a0a7f839 /enum.c | |
parent | c7761bbfa1a0212df9eb49d921eb12b2bc1a241a (diff) | |
download | ruby-c032557a66a6d37670850a8352768de8e4199e9f.tar.gz ruby-c032557a66a6d37670850a8352768de8e4199e9f.tar.xz ruby-c032557a66a6d37670850a8352768de8e4199e9f.zip |
* enum.c (enum_take): get rid of extraneous iteration.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18727 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'enum.c')
-rw-r--r-- | enum.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -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; } @@ -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]; } |