From ecb93c3fdf347a3d14c13f8f9292bebf77ebfa07 Mon Sep 17 00:00:00 2001 From: matz Date: Mon, 6 Aug 2007 16:53:36 +0000 Subject: * enum.c (enum_zip): zip no longer converts arguments into arrays, uses enumerators. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@12892 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- enum.c | 56 ++++++++++++++++++++++++++++++-------------------------- 1 file changed, 30 insertions(+), 26 deletions(-) (limited to 'enum.c') diff --git a/enum.c b/enum.c index 3ca42ca4bd..fa58762463 100644 --- a/enum.c +++ b/enum.c @@ -15,7 +15,7 @@ #include "ruby/util.h" VALUE rb_mEnumerable; -static ID id_each, id_eqq, id_cmp; +static ID id_each, id_eqq, id_cmp, id_next; static VALUE grep_i(VALUE i, VALUE *arg) @@ -1348,20 +1348,20 @@ enum_each_with_index(int argc, VALUE *argv, VALUE obj) } static VALUE -zip_i(VALUE val, VALUE *memo) +zip_i(VALUE val, NODE *memo) { - VALUE result = memo[0]; - VALUE args = memo[1]; - int idx = memo[2]++; - VALUE tmp; + volatile VALUE result = memo->u1.value; + volatile VALUE args = memo->u2.value; + volatile VALUE tmp; int i; tmp = rb_ary_new2(RARRAY_LEN(args) + 1); rb_ary_store(tmp, 0, val); for (i=0; iu3.value, id_each, 0, 0, zip_i, (VALUE)memo); +} + /* * call-seq: - * enum.zip(arg, ...) => array + * enum.zip(arg, ...) => enumerator * enum.zip(arg, ...) {|arr| block } => nil * - * Converts any arguments to arrays, then merges elements of - * enum with corresponding elements from each argument. This - * generates a sequence of enum#size n-element - * arrays, where n is one more that the count of arguments. If - * the size of any argument is less than enum#size, - * nil values are supplied. If a block given, it is - * invoked for each output array, otherwise an array of arrays is - * returned. + * Takes one element from enum and merges corresponding + * elements from each args. This generates a sequence of + * n-element arrays, where n is one more that the + * count of arguments. The length of the sequence is truncated to + * the size of the shortest argument (or enum). If a block + * given, it is invoked for each output array, otherwise an array of + * arrays is returned. * * a = [ 4, 5, 6 ] * b = [ 7, 8, 9 ] * - * (1..3).zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] - * "cat\ndog".zip([1]) #=> [["cat\n", 1], ["dog", nil]] - * (1..3).zip #=> [[1], [2], [3]] + * [1,2,3].zip(a, b) #=> [[1, 4, 7], [2, 5, 8], [3, 6, 9]] + * [1,2].zip(a,b) #=> [[1, 4, 7], [2, 5, 8]] + * a.zip([1,2],[8]) #=> [[4,1,8]] * */ @@ -1398,17 +1403,15 @@ enum_zip(int argc, VALUE *argv, VALUE obj) { int i; VALUE result; - VALUE memo[3]; + NODE *memo; for (i=0; i"); + id_next = rb_intern("next"); } -- cgit v1.2.3