ruby-changes:18127
From: matz <ko1@a...>
Date: Thu, 9 Dec 2010 15:47:29 +0900 (JST)
Subject: [ruby-changes:18127] Ruby:r30148 (trunk): * array.c (rb_ary_dup): should copy contents only. no instance
matz 2010-12-09 15:46:25 +0900 (Thu, 09 Dec 2010) New Revision: 30148 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=30148 Log: * array.c (rb_ary_dup): should copy contents only. no instance variable, no class would be copied. it would affect methods #sort, #reject, #transpose, #uniq, #compact, and #shuffle. [ruby-core:33640] * array.c (rb_ary_reverse_m): ditto. * array.c (rb_ary_rotate_m): ditto. Modified files: trunk/ChangeLog trunk/array.c Index: array.c =================================================================== --- array.c (revision 30147) +++ array.c (revision 30148) @@ -1527,22 +1527,12 @@ return Qfalse; } -static VALUE -rb_ary_dup_setup(VALUE ary) -{ - VALUE dup = rb_ary_new2(RARRAY_LEN(ary)); - int is_embed = ARY_EMBED_P(dup); - DUPSETUP(dup, ary); - if (is_embed) FL_SET_EMBED(dup); - ARY_SET_LEN(dup, RARRAY_LEN(ary)); - return dup; -} - VALUE rb_ary_dup(VALUE ary) { - VALUE dup = rb_ary_dup_setup(ary); + VALUE dup = rb_ary_new2(RARRAY_LEN(ary)); MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary)); + ARY_SET_LEN(dup, RARRAY_LEN(ary)); return dup; } @@ -1830,14 +1820,15 @@ static VALUE rb_ary_reverse_m(VALUE ary) { - VALUE dup = rb_ary_dup_setup(ary); long len = RARRAY_LEN(ary); + VALUE dup = rb_ary_new2(len); if (len > 0) { VALUE *p1 = RARRAY_PTR(ary); VALUE *p2 = RARRAY_PTR(dup) + len - 1; do *p2-- = *p1++; while (--len > 0); } + ARY_SET_LEN(dup, RARRAY_LEN(ary)); return dup; } @@ -1925,7 +1916,7 @@ } len = RARRAY_LEN(ary); - rotated = rb_ary_dup_setup(ary); + rotated = rb_ary_new2(len); if (len > 0) { cnt = rotate_count(cnt, len); ptr = RARRAY_PTR(ary); @@ -1934,6 +1925,7 @@ MEMCPY(ptr2, ptr + cnt, VALUE, len); MEMCPY(ptr2 + len, ptr, VALUE, cnt); } + ARY_SET_LEN(rotated, RARRAY_LEN(ary)); return rotated; } Index: ChangeLog =================================================================== --- ChangeLog (revision 30147) +++ ChangeLog (revision 30148) @@ -1,3 +1,14 @@ +Thu Dec 9 11:00:30 2010 Yukihiro Matsumoto <matz@r...> + + * array.c (rb_ary_dup): should copy contents only. no instance + variable, no class would be copied. it would affect methods + #sort, #reject, #transpose, #uniq, #compact, and #shuffle. + [ruby-core:33640] + + * array.c (rb_ary_reverse_m): ditto. + + * array.c (rb_ary_rotate_m): ditto. + Wed Dec 8 21:38:40 2010 NARUSE, Yui <naruse@r...> * ext/dl/lib/dl/struct.rb: clean a warning: assigned but unused -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/