summaryrefslogtreecommitdiff
path: root/array.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-03 05:20:14 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-09-03 05:20:14 +0000
commit6f484e4930be69c58462dd11c97663e6c8488b8e (patch)
tree324b1dbdf4149be943eb3cbff26ad7f377e53dc0 /array.c
parent20254d4e133331e69e6aa7514e1e72ad7d14d496 (diff)
* variable.c (rb_copy_generic_ivar): remove old generic instance
variable table if it existes. * class.c (rb_make_metaclass): metaclass of a metaclass is a metaclass itself. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2784 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'array.c')
-rw-r--r--array.c38
1 files changed, 15 insertions, 23 deletions
diff --git a/array.c b/array.c
index f247db9794..ee59769a5c 100644
--- a/array.c
+++ b/array.c
@@ -795,22 +795,6 @@ rb_ary_empty_p(ary)
return Qfalse;
}
-static VALUE
-rb_ary_become(copy, orig)
- VALUE copy, orig;
-{
- orig = to_ary(orig);
- ary_make_shared(orig);
- if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
- free(RARRAY(copy)->ptr);
- RARRAY(copy)->ptr = RARRAY(orig)->ptr;
- RARRAY(copy)->len = RARRAY(orig)->len;
- RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
- FL_SET(copy, ELTS_SHARED);
-
- return copy;
-}
-
VALUE
rb_ary_dup(ary)
VALUE ary;
@@ -1316,13 +1300,21 @@ rb_ary_delete_if(ary)
}
static VALUE
-rb_ary_replace(ary, ary2)
- VALUE ary, ary2;
+rb_ary_replace(copy, orig)
+ VALUE copy, orig;
{
- if (ary == ary2) return ary;
- ary2 = to_ary(ary2);
- rb_ary_update(ary, 0, RARRAY(ary)->len, ary2);
- return ary;
+ rb_ary_modify(copy);
+ orig = to_ary(orig);
+ if (copy == orig) return copy;
+ ary_make_shared(orig);
+ if (RARRAY(copy)->ptr && !FL_TEST(copy, ELTS_SHARED))
+ free(RARRAY(copy)->ptr);
+ RARRAY(copy)->ptr = RARRAY(orig)->ptr;
+ RARRAY(copy)->len = RARRAY(orig)->len;
+ RARRAY(copy)->aux.shared = RARRAY(orig)->aux.shared;
+ FL_SET(copy, ELTS_SHARED);
+
+ return copy;
}
VALUE
@@ -1857,7 +1849,7 @@ Init_Array()
rb_define_method(rb_cArray, "rindex", rb_ary_rindex, 1);
rb_define_method(rb_cArray, "indexes", rb_ary_indexes, -1);
rb_define_method(rb_cArray, "indices", rb_ary_indexes, -1);
- rb_define_method(rb_cArray, "become", rb_ary_become, 1);
+ rb_define_method(rb_cArray, "become", rb_ary_replace, 1);
rb_define_method(rb_cArray, "join", rb_ary_join_m, -1);
rb_define_method(rb_cArray, "reverse", rb_ary_reverse_m, 0);
rb_define_method(rb_cArray, "reverse!", rb_ary_reverse_bang, 0);