mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* array.c (rb_ary_permutation): small dirty hack by Matz to avoid
arrays on stack. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13591 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
04bc87e582
commit
209b950f3f
2 changed files with 8 additions and 2 deletions
|
@ -6,6 +6,9 @@ Tue Oct 2 08:25:50 2007 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
* array.c (rb_ary_combination): RDoc update to clarify. a patch
|
* array.c (rb_ary_combination): RDoc update to clarify. a patch
|
||||||
from David Flanagan. [ruby-core:12344]
|
from David Flanagan. [ruby-core:12344]
|
||||||
|
|
||||||
|
* array.c (rb_ary_permutation): small dirty hack by Matz to avoid
|
||||||
|
arrays on stack.
|
||||||
|
|
||||||
Tue Oct 2 07:01:05 2007 Koichi Sasada <ko1@atdot.net>
|
Tue Oct 2 07:01:05 2007 Koichi Sasada <ko1@atdot.net>
|
||||||
|
|
||||||
* proc.c (proc_dup): proc->block.proc should be self.
|
* proc.c (proc_dup): proc->block.proc should be self.
|
||||||
|
|
7
array.c
7
array.c
|
@ -3036,8 +3036,11 @@ rb_ary_permutation(VALUE ary, VALUE num)
|
||||||
}
|
}
|
||||||
else { /* this is the general case */
|
else { /* this is the general case */
|
||||||
ary = rb_ary_dup(ary); /* private defensive copy of ary */
|
ary = rb_ary_dup(ary); /* private defensive copy of ary */
|
||||||
long p[n];
|
volatile VALUE t0 = rb_str_new(0, n*sizeof(long));
|
||||||
int used[n];
|
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 */
|
||||||
|
|
||||||
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
|
for(i = 0; i < n; i++) used[i] = 0; /* initialize array */
|
||||||
|
|
||||||
permute0(n,r,p,0,used,ary); /* compute and yield permutations */
|
permute0(n,r,p,0,used,ary); /* compute and yield permutations */
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue