mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* 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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@30148 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
fc2748e71e
commit
11b3b5ed90
2 changed files with 17 additions and 14 deletions
11
ChangeLog
11
ChangeLog
|
@ -1,3 +1,14 @@
|
|||
Thu Dec 9 11:00:30 2010 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||
|
||||
* 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@ruby-lang.org>
|
||||
|
||||
* ext/dl/lib/dl/struct.rb: clean a warning: assigned but unused
|
||||
|
|
20
array.c
20
array.c
|
@ -1527,22 +1527,12 @@ rb_ary_empty_p(VALUE ary)
|
|||
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 @@ rb_ary_reverse_bang(VALUE ary)
|
|||
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 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
|
|||
}
|
||||
|
||||
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 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
|
|||
MEMCPY(ptr2, ptr + cnt, VALUE, len);
|
||||
MEMCPY(ptr2 + len, ptr, VALUE, cnt);
|
||||
}
|
||||
ARY_SET_LEN(rotated, RARRAY_LEN(ary));
|
||||
return rotated;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue