# Array#dup\$B\$,\$*\$+\$7\$\$(B?

#1

e\$B\$3\$s\$K\$A\$O;3K\$H\$b\$&\$7\$^\$9!#e(B

trunke\$B\$Ne(Brubye\$B\$r;n\$7\$F\$?\$s\$G\$9\$,e(BArray#dupe\$B\$,\$*\$+\$7\$\$\$h\$&\$G\$9!#e(B

./miniruby -e ‘p ([0,1][0,1]).dup’
#[0, 1]e\$B\$HI=<(\$5\$l\$ke(B

e\$B0J2<\$N\$h\$&\$K\$7\$F\$bF1\$8\$G\$7\$?!#e(B

a = [0,1]
p a[0,1] #[0]e\$B\$HI=<(\$5\$l\$ke(B
p a[0,1].dup #[0, 1]e\$B\$HI=<(\$5\$l\$ke(B

e\$B4D6-\$Oe(B

ruby 1.9.0 (2007-01-09 patchlevel 0) [i686-linux]

e\$B\$G\$9!#e(B

#2

e\$B\$J\$+\$@\$G\$9!#e(B

At Tue, 9 Jan 2007 17:41:05 +0900,

trunke\$B\$Ne(Brubye\$B\$r;n\$7\$F\$?\$s\$G\$9\$,e(BArray#dupe\$B\$,\$*\$+\$7\$\$\$h\$&\$G\$9!#e(B

./miniruby -e ‘p ([0,1][0,1]).dup’
#[0, 1]e\$B\$HI=<(\$5\$l\$ke(B

lfreee\$B\$re(Breverte\$B\$7\$?\$H\$-\$N%_%9\$G\$7\$g\$&\$+!#e(B

# Index: array.c

— array.c (revision 11516)
+++ array.c (working copy)
@@ -2091,13 +2091,15 @@ rb_ary_replace(VALUE copy, VALUE orig)
VALUE *ptr;

• rb_ary_modify(copy);
• ary_iter_check(copy);
orig = to_ary(orig);
• rb_ary_modify_check(copy);
• ary_iter_check(copy);
if (copy == orig) return copy;
shared = ary_make_shared(orig);
• ptr = RARRAY(copy)->ptr;
• if (!ARY_SHARED_P(copy)) {
• ptr = RARRAY(copy)->ptr;
xfree(ptr);
• RARRAY(copy)->ptr = RARRAY(shared)->ptr;
• RARRAY(copy)->len = RARRAY(shared)->len;
• }
• RARRAY(copy)->ptr = RARRAY(orig)->ptr;
• RARRAY(copy)->len = RARRAY(orig)->len;
RARRAY(copy)->aux.shared = shared;
FL_SET(copy, ELTS_SHARED);

#3

e\$B\$^\$D\$b\$He(B e\$B\$f\$-\$R\$m\$G\$9e(B

In message “Re: [ruby-dev:30117] Re: Array#dupe\$B\$,\$*\$+\$7\$\$e(B?”
on Tue, 9 Jan 2007 19:02:10 +0900, “Nobuyoshi N.”