mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c: remove to_a completely.
* array.c (tmpbuf): keep DRY to clear klass of temporary objects. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13666 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
44ee78db94
commit
1c65de7284
2 changed files with 23 additions and 19 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
Tue Oct 9 16:58:10 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* array.c: remove to_a completely.
|
||||||
|
|
||||||
|
* array.c (tmpbuf): keep DRY to clear klass of temporary objects.
|
||||||
|
|
||||||
Tue Oct 9 16:33:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
Tue Oct 9 16:33:32 2007 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* array.c (rb_ary_permutation, rb_ary_combination, rb_ary_product):
|
* array.c (rb_ary_permutation, rb_ary_combination, rb_ary_product):
|
||||||
|
|
36
array.c
36
array.c
|
@ -231,14 +231,6 @@ to_ary(VALUE ary)
|
||||||
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
|
return rb_convert_type(ary, T_ARRAY, "Array", "to_ary");
|
||||||
}
|
}
|
||||||
|
|
||||||
#if 0
|
|
||||||
static VALUE
|
|
||||||
to_a(VALUE ary)
|
|
||||||
{
|
|
||||||
return rb_convert_type(ary, T_ARRAY, "Array", "to_a");
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_check_array_type(VALUE ary)
|
rb_check_array_type(VALUE ary)
|
||||||
{
|
{
|
||||||
|
@ -2956,6 +2948,15 @@ rb_ary_cycle(VALUE ary)
|
||||||
return Qnil;
|
return Qnil;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static VALUE
|
||||||
|
tmpbuf(int n, int size)
|
||||||
|
{
|
||||||
|
VALUE buf = rb_str_new(0, n*size);
|
||||||
|
|
||||||
|
RBASIC(buf)->klass = 0;
|
||||||
|
return buf;
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Recursively compute permutations of r elements of the set [0..n-1].
|
* Recursively compute permutations of r elements of the set [0..n-1].
|
||||||
* When we have a complete permutation of array indexes, copy the values
|
* When we have a complete permutation of array indexes, copy the values
|
||||||
|
@ -3039,13 +3040,11 @@ rb_ary_permutation(VALUE ary, VALUE num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else { /* this is the general case */
|
else { /* this is the general case */
|
||||||
volatile VALUE t0 = rb_str_new(0, n*sizeof(long));
|
volatile t0 = tmpbuf(n,sizeof(long));
|
||||||
long *p = (long*)RSTRING_PTR(t0); /* array indexes of current permutation */
|
long *p = (long*)RSTRING_PTR(t0);
|
||||||
volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
|
volatile t1 = tmpbuf(n,sizeof(int));
|
||||||
int *used = (int*)RSTRING_PTR(t1); /* booleans: which indexes are already used */
|
int *used = (int*)RSTRING_PTR(t0);
|
||||||
|
|
||||||
RBASIC(t0)->klass = 0;
|
|
||||||
RBASIC(t1)->klass = 0;
|
|
||||||
ary = rb_ary_dup(ary); /* private defensive copy of ary */
|
ary = rb_ary_dup(ary); /* private defensive copy of ary */
|
||||||
|
|
||||||
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
|
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
|
||||||
|
@ -3114,14 +3113,13 @@ rb_ary_combination(VALUE ary, VALUE num)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
volatile VALUE tmp = rb_str_new(0, n*sizeof(long));
|
volatile t0 = tmpbuf(n, sizeof(long));
|
||||||
long *stack = (long*)RSTRING_PTR(tmp);
|
long *stack = (long*)RSTRING_PTR(t0);
|
||||||
long nlen = combi_len(len, n);
|
long nlen = combi_len(len, n);
|
||||||
volatile VALUE cc = rb_ary_new2(n);
|
volatile VALUE cc = rb_ary_new2(n);
|
||||||
VALUE *chosen = RARRAY_PTR(cc);
|
VALUE *chosen = RARRAY_PTR(cc);
|
||||||
long lev = 0;
|
long lev = 0;
|
||||||
|
|
||||||
RBASIC(tmp)->klass = 0;
|
|
||||||
RBASIC(cc)->klass = 0;
|
RBASIC(cc)->klass = 0;
|
||||||
MEMZERO(stack, long, n);
|
MEMZERO(stack, long, n);
|
||||||
stack[0] = -1;
|
stack[0] = -1;
|
||||||
|
@ -3159,8 +3157,8 @@ static VALUE
|
||||||
rb_ary_product(int argc, VALUE *argv, VALUE ary)
|
rb_ary_product(int argc, VALUE *argv, VALUE ary)
|
||||||
{
|
{
|
||||||
int n = argc+1; /* How many arrays we're operating on */
|
int n = argc+1; /* How many arrays we're operating on */
|
||||||
volatile VALUE t0 = rb_str_new(0, n*sizeof(VALUE));
|
volatile VALUE t0 = tmpbuf(n, sizeof(VALUE));
|
||||||
volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
|
volatile VALUE t1 = tmpbuf(n, sizeof(int));
|
||||||
VALUE *arrays = (VALUE*)RSTRING_PTR(t0); /* The arrays we're computing the product of */
|
VALUE *arrays = (VALUE*)RSTRING_PTR(t0); /* The arrays we're computing the product of */
|
||||||
int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
|
int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
|
||||||
VALUE result; /* The array we'll be returning */
|
VALUE result; /* The array we'll be returning */
|
||||||
|
|
Loading…
Reference in a new issue