зеркало из https://github.com/github/ruby.git
* array.c (rb_ary_zip): some refactoring.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43468 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
Родитель
806b93ed9b
Коммит
887ff70f23
|
@ -1,3 +1,7 @@
|
|||
Tue Oct 29 23:01:18 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* array.c (rb_ary_zip): some refactoring.
|
||||
|
||||
Tue Oct 29 22:11:37 2013 Masaki Matsushita <glass.saga@gmail.com>
|
||||
|
||||
* array.c (rb_ary_uniq_bang): use st_foreach() instead of for loop.
|
||||
|
|
49
array.c
49
array.c
|
@ -3217,44 +3217,51 @@ take_items(VALUE obj, long n)
|
|||
static VALUE
|
||||
rb_ary_zip(int argc, VALUE *argv, VALUE ary)
|
||||
{
|
||||
int i, j, block_given, arity = 0;
|
||||
long len;
|
||||
int i, j;
|
||||
long len = RARRAY_LEN(ary);
|
||||
VALUE result = Qnil;
|
||||
|
||||
len = RARRAY_LEN(ary);
|
||||
for (i=0; i<argc; i++) {
|
||||
argv[i] = take_items(argv[i], len);
|
||||
}
|
||||
|
||||
block_given = rb_block_given_p();
|
||||
if (block_given)
|
||||
arity = rb_block_arity();
|
||||
else
|
||||
result = rb_ary_new2(len);
|
||||
if (rb_block_given_p()) {
|
||||
int arity = rb_block_arity();
|
||||
|
||||
if (block_given && arity > 1 && argc+1 < 0x100) {
|
||||
VALUE *tmp = ALLOCA_N(VALUE, argc+1);
|
||||
if (arity > 1 && argc+1 < 0x100) {
|
||||
VALUE *tmp = ALLOCA_N(VALUE, argc+1);
|
||||
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
tmp[0] = RARRAY_AREF(ary, i);
|
||||
for (j=0; j<argc; j++) {
|
||||
tmp[j+1] = rb_ary_elt(argv[j], i);
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
tmp[0] = RARRAY_AREF(ary, i);
|
||||
for (j=0; j<argc; j++) {
|
||||
tmp[j+1] = rb_ary_elt(argv[j], i);
|
||||
}
|
||||
rb_yield_values2(argc+1, tmp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
VALUE tmp = rb_ary_new2(argc+1);
|
||||
|
||||
rb_ary_push(tmp, RARRAY_AREF(ary, i));
|
||||
for (j=0; j<argc; j++) {
|
||||
rb_ary_push(tmp, rb_ary_elt(argv[j], i));
|
||||
}
|
||||
rb_yield(tmp);
|
||||
}
|
||||
rb_yield_values2(argc+1, tmp);
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (i=0; i<RARRAY_LEN(ary); i++) {
|
||||
VALUE tmp = rb_ary_new2(argc+1);
|
||||
result = rb_ary_new_capa(len);
|
||||
|
||||
for (i=0; i<len; i++) {
|
||||
VALUE tmp = rb_ary_new_capa(argc+1);
|
||||
|
||||
rb_ary_push(tmp, RARRAY_AREF(ary, i));
|
||||
for (j=0; j<argc; j++) {
|
||||
rb_ary_push(tmp, rb_ary_elt(argv[j], i));
|
||||
}
|
||||
if (block_given)
|
||||
rb_yield(tmp);
|
||||
else
|
||||
rb_ary_push(result, tmp);
|
||||
rb_ary_push(result, tmp);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Загрузка…
Ссылка в новой задаче