From c45908e41f47c88674b73a754ecd0535449b667a Mon Sep 17 00:00:00 2001 From: matz Date: Tue, 27 Aug 2002 08:31:08 +0000 Subject: * file.c (rb_find_file): $LOAD_PATH must not be empty. * file.c (rb_find_file_ext): ditto. * range.c (range_eq): class check should be based on range.class, instead of Range to work with Range.dup. * range.c (range_eql): ditto. * class.c (rb_mod_dup): need to preserve metaclass and flags. * object.c (rb_cstr_to_dbl): had a buffer overrun. * marshal.c (w_class): integrate singleton check into a funciton to follow DRY principle. * marshal.c (w_uclass): should check singleton method. * object.c (rb_obj_dup): dmark and dfree functions must be match for T_DATA type. * object.c (rb_obj_dup): class of the duped object must be match to the class of the original. * re.c (rb_reg_quote): do not escape \t, \f, \r, \n, for they are not regular expression metacharacters. * time.c (time_s_alloc): use time_free instead of free (null check, also serves for type mark). * time.c (time_s_at): check dfree function too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2748 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- array.c | 51 ++++++++++++++++----------------------------------- 1 file changed, 16 insertions(+), 35 deletions(-) (limited to 'array.c') diff --git a/array.c b/array.c index 0f016eb1a4..f88e1b1cc2 100644 --- a/array.c +++ b/array.c @@ -796,41 +796,23 @@ rb_ary_empty_p(ary) } static VALUE -ary_copy(ary, clone) - VALUE ary; - int clone; -{ - VALUE copy; - - ary_make_shared(ary); - copy = rb_obj_alloc(rb_cArray); - if (clone) CLONESETUP(copy, ary); - else DUPSETUP(copy, ary); - RARRAY(copy)->ptr = RARRAY(ary)->ptr; - RARRAY(copy)->len = RARRAY(ary)->len; - RARRAY(copy)->aux.shared = RARRAY(ary)->aux.shared; +rb_ary_become(copy, orig) + VALUE copy, orig; +{ + orig = to_ary(orig); + ary_make_shared(orig); + if (RARRAY(copy)->ptr) 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; } -static VALUE -rb_ary_clone(ary) - VALUE ary; -{ - return ary_copy(ary, Qtrue); -} - VALUE rb_ary_dup(ary) VALUE ary; -{ - return ary_copy(ary, Qfalse); -} - -static VALUE -ary_dup(ary) - VALUE ary; { VALUE dup = rb_ary_new2(RARRAY(ary)->len); @@ -1059,7 +1041,7 @@ static VALUE rb_ary_reverse_m(ary) VALUE ary; { - return rb_ary_reverse(ary_dup(ary)); + return rb_ary_reverse(rb_ary_dup(ary)); } int @@ -1137,7 +1119,7 @@ VALUE rb_ary_sort(ary) VALUE ary; { - ary = ary_dup(ary); + ary = rb_ary_dup(ary); rb_ary_sort_bang(ary); return ary; } @@ -1319,7 +1301,7 @@ static VALUE rb_ary_reject(ary) VALUE ary; { - ary = ary_dup(ary); + ary = rb_ary_dup(ary); rb_ary_reject_bang(ary); return ary; } @@ -1715,7 +1697,7 @@ static VALUE rb_ary_uniq(ary) VALUE ary; { - ary = ary_dup(ary); + ary = rb_ary_dup(ary); rb_ary_uniq_bang(ary); return ary; } @@ -1747,7 +1729,7 @@ static VALUE rb_ary_compact(ary) VALUE ary; { - ary = ary_dup(ary); + ary = rb_ary_dup(ary); rb_ary_compact_bang(ary); return ary; } @@ -1826,7 +1808,7 @@ static VALUE rb_ary_flatten(ary) VALUE ary; { - ary = ary_dup(ary); + ary = rb_ary_dup(ary); rb_ary_flatten_bang(ary); return ary; } @@ -1874,8 +1856,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, "clone", rb_ary_clone, 0); - rb_define_method(rb_cArray, "dup", rb_ary_dup, 0); + rb_define_method(rb_cArray, "become", rb_ary_become, 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); -- cgit v1.2.3