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

* array.c (permute0): use chars for boolean array.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24365 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2009-08-03 06:56:57 +00:00
parent 49816a2552
commit 34401f9014
2 changed files with 7 additions and 5 deletions

View file

@ -1,4 +1,6 @@
Mon Aug 3 15:48:40 2009 Nobuyoshi Nakada <nobu@ruby-lang.org> Mon Aug 3 15:56:52 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
* array.c (permute0): use chars for boolean array.
* array.c (rb_ary_{permutation,combination}): disallow reentrance * array.c (rb_ary_{permutation,combination}): disallow reentrance
with continuation since work-buffers cannot restore. with continuation since work-buffers cannot restore.

View file

@ -3664,7 +3664,7 @@ rb_ary_cycle(int argc, VALUE *argv, VALUE ary)
* values: the Ruby array that holds the actual values to permute * values: the Ruby array that holds the actual values to permute
*/ */
static void static void
permute0(long n, long r, long *p, long index, int *used, VALUE values) permute0(long n, long r, long *p, long index, char *used, VALUE values)
{ {
long i,j; long i,j;
for (i = 0; i < n; i++) { for (i = 0; i < n; i++) {
@ -3746,12 +3746,12 @@ rb_ary_permutation(int argc, VALUE *argv, VALUE ary)
else { /* this is the general case */ else { /* this is the general case */
volatile VALUE t0 = tmpbuf(n,sizeof(long)); volatile VALUE t0 = tmpbuf(n,sizeof(long));
long *p = (long*)RSTRING_PTR(t0); long *p = (long*)RSTRING_PTR(t0);
volatile VALUE t1 = tmpbuf(n,sizeof(int)); volatile VALUE t1 = tmpbuf(n,sizeof(char));
int *used = (int*)RSTRING_PTR(t1); char *used = (char*)RSTRING_PTR(t1);
VALUE ary0 = ary_make_substitution(ary); /* private defensive copy of ary */ VALUE ary0 = ary_make_substitution(ary); /* private defensive copy of ary */
RBASIC(ary0)->klass = 0; RBASIC(ary0)->klass = 0;
for (i = 0; i < n; i++) used[i] = 0; /* initialize array */ MEMZERO(used, char, n); /* initialize array */
permute0(n, r, p, 0, used, ary0); /* compute and yield permutations */ permute0(n, r, p, 0, used, ary0); /* compute and yield permutations */
tmpbuf_discard(t0); tmpbuf_discard(t0);