Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

* 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
  • Loading branch information...
commit 11b3b5ed9024fa0d02400f90373269c0b91bbddf 1 parent fc2748e
authored

Showing 2 changed files with 17 additions and 14 deletions. Show diff stats Hide diff stats

  1. 11  ChangeLog
  2. 20  array.c
11  ChangeLog
... ...
@@ -1,3 +1,14 @@
  1
+Thu Dec  9 11:00:30 2010  Yukihiro Matsumoto  <matz@ruby-lang.org>
  2
+
  3
+	* array.c (rb_ary_dup): should copy contents only.  no instance
  4
+	  variable, no class would be copied.  it would affect methods
  5
+	  #sort, #reject, #transpose, #uniq, #compact, and #shuffle.
  6
+	  [ruby-core:33640]
  7
+
  8
+	* array.c (rb_ary_reverse_m): ditto.
  9
+
  10
+	* array.c (rb_ary_rotate_m): ditto.
  11
+
1 12
 Wed Dec  8 21:38:40 2010  NARUSE, Yui  <naruse@ruby-lang.org>
2 13
 
3 14
 	* ext/dl/lib/dl/struct.rb: clean a warning: assigned but unused
20  array.c
@@ -1527,22 +1527,12 @@ rb_ary_empty_p(VALUE ary)
1527 1527
     return Qfalse;
1528 1528
 }
1529 1529
 
1530  
-static VALUE
1531  
-rb_ary_dup_setup(VALUE ary)
1532  
-{
1533  
-    VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
1534  
-    int is_embed = ARY_EMBED_P(dup);
1535  
-    DUPSETUP(dup, ary);
1536  
-    if (is_embed) FL_SET_EMBED(dup);
1537  
-    ARY_SET_LEN(dup, RARRAY_LEN(ary));
1538  
-    return dup;
1539  
-}
1540  
-
1541 1530
 VALUE
1542 1531
 rb_ary_dup(VALUE ary)
1543 1532
 {
1544  
-    VALUE dup = rb_ary_dup_setup(ary);
  1533
+    VALUE dup = rb_ary_new2(RARRAY_LEN(ary));
1545 1534
     MEMCPY(RARRAY_PTR(dup), RARRAY_PTR(ary), VALUE, RARRAY_LEN(ary));
  1535
+    ARY_SET_LEN(dup, RARRAY_LEN(ary));
1546 1536
     return dup;
1547 1537
 }
1548 1538
 
@@ -1830,14 +1820,15 @@ rb_ary_reverse_bang(VALUE ary)
1830 1820
 static VALUE
1831 1821
 rb_ary_reverse_m(VALUE ary)
1832 1822
 {
1833  
-    VALUE dup = rb_ary_dup_setup(ary);
1834 1823
     long len = RARRAY_LEN(ary);
  1824
+    VALUE dup = rb_ary_new2(len);
1835 1825
 
1836 1826
     if (len > 0) {
1837 1827
 	VALUE *p1 = RARRAY_PTR(ary);
1838 1828
 	VALUE *p2 = RARRAY_PTR(dup) + len - 1;
1839 1829
 	do *p2-- = *p1++; while (--len > 0);
1840 1830
     }
  1831
+    ARY_SET_LEN(dup, RARRAY_LEN(ary));
1841 1832
     return dup;
1842 1833
 }
1843 1834
 
@@ -1925,7 +1916,7 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
1925 1916
     }
1926 1917
 
1927 1918
     len = RARRAY_LEN(ary);
1928  
-    rotated = rb_ary_dup_setup(ary);
  1919
+    rotated = rb_ary_new2(len);
1929 1920
     if (len > 0) {
1930 1921
 	cnt = rotate_count(cnt, len);
1931 1922
 	ptr = RARRAY_PTR(ary);
@@ -1934,6 +1925,7 @@ rb_ary_rotate_m(int argc, VALUE *argv, VALUE ary)
1934 1925
 	MEMCPY(ptr2, ptr + cnt, VALUE, len);
1935 1926
 	MEMCPY(ptr2 + len, ptr, VALUE, cnt);
1936 1927
     }
  1928
+    ARY_SET_LEN(rotated, RARRAY_LEN(ary));
1937 1929
     return rotated;
1938 1930
 }
1939 1931
 

0 notes on commit 11b3b5e

Please sign in to comment.
Something went wrong with that request. Please try again.