From 7550659a330c099b31c047293a8ab486b8638c8a Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 9 Oct 2007 12:35:31 +0000 Subject: [PATCH] * array.c (rb_ary_permutation): use frozen shared hidden array. [ruby-dev:31985] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@13668 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 5 ++++- array.c | 7 +++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 7e79830954..fa3efcfa6b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,10 +1,13 @@ -Tue Oct 9 21:29:19 2007 Nobuyoshi Nakada +Tue Oct 9 21:35:28 2007 Nobuyoshi Nakada * array.c (rb_ary_permutation, rb_ary_combination): missing type names. * array.c (rb_ary_permutation): used buffer should be t1. + * array.c (rb_ary_permutation): use frozen shared hidden array. + [ruby-dev:31985] + Tue Oct 9 16:58:10 2007 Yukihiro Matsumoto * array.c: remove to_a completely. diff --git a/array.c b/array.c index 13e848949e..6360571e40 100644 --- a/array.c +++ b/array.c @@ -2988,7 +2988,7 @@ permute0(long n, long r, long *p, long index, int *used, VALUE values) /* And yield it to the associated block */ VALUE result = rb_ary_new2(r); VALUE *result_array = RARRAY_PTR(result); - VALUE *values_array = RARRAY_PTR(values); + const VALUE *values_array = RARRAY_PTR(values); for (j = 0; j < r; j++) result_array[j] = values_array[p[j]]; RARRAY(result)->len = r; @@ -3044,12 +3044,11 @@ rb_ary_permutation(VALUE ary, VALUE num) long *p = (long*)RSTRING_PTR(t0); volatile VALUE t1 = tmpbuf(n,sizeof(int)); int *used = (int*)RSTRING_PTR(t1); - - ary = rb_ary_dup(ary); /* private defensive copy of ary */ + VALUE ary0 = ary_make_shared(ary); /* private defensive copy of ary */ 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, ary0); /* compute and yield permutations */ } return ary; }