1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_permutation, rb_ary_product): support non C99

compilers.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13625 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
usa 2007-10-04 11:18:14 +00:00
parent 1d758debe0
commit b618f011b7
2 changed files with 9 additions and 3 deletions

View file

@ -1,3 +1,8 @@
Thu Oct 4 20:17:19 2007 NAKAMURA Usaku <usa@ruby-lang.org>
* array.c (rb_ary_permutation, rb_ary_product): support non C99
compilers.
Thu Oct 4 17:33:18 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
* re.c (kcode_setter): Perl-ish global variable `$=' no longer

View file

@ -3037,11 +3037,11 @@ rb_ary_permutation(VALUE ary, VALUE num)
}
}
else { /* this is the general case */
ary = rb_ary_dup(ary); /* private defensive copy of ary */
volatile VALUE t0 = rb_str_new(0, n*sizeof(long));
long *p = (long*)RSTRING_PTR(t0); /* array indexes of current permutation */
volatile VALUE t1 = rb_str_new(0, n*sizeof(int));
int *used = (int*)RSTRING_PTR(t1); /* booleans: which indexes are already used */
ary = rb_ary_dup(ary); /* private defensive copy of ary */
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
@ -3158,6 +3158,7 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
int *counters = (int*)RSTRING_PTR(t1); /* The current position in each one */
VALUE result; /* The array we'll be returning */
long i,j;
long resultlen = 1;
/* initialize the arrays of arrays */
arrays[0] = ary;
@ -3167,7 +3168,6 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
for(i = 0; i < n; i++) counters[i] = 0;
/* Compute the length of the result array; return [] if any is empty */
long resultlen = 1;
for(i = 0; i < n; i++) {
resultlen *= RARRAY_LEN(arrays[i]);
if (resultlen == 0) return rb_ary_new2(0);
@ -3176,6 +3176,7 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
/* Otherwise, allocate and fill in an array of results */
result = rb_ary_new2(resultlen);
for(i = 0; i < resultlen; i++) {
int m;
/* fill in one subarray */
VALUE subarray = rb_ary_new2(n);
for(j = 0; j < n; j++) {
@ -3189,7 +3190,7 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
* Increment the last counter. If it overflows, reset to 0
* and increment the one before it.
*/
int m = n-1;
m = n-1;
counters[m]++;
while(m >= 0 && counters[m] == RARRAY_LEN(arrays[m])) {
counters[m] = 0;