ruby-changes:11557
From: mame <ko1@a...>
Date: Wed, 15 Apr 2009 20:48:08 +0900 (JST)
Subject: [ruby-changes:11557] Ruby:r23191 (trunk): * array.c (rb_ary_flatten): flatten(0) works as Array#dup.
mame 2009-04-15 20:47:54 +0900 (Wed, 15 Apr 2009) New Revision: 23191 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23191 Log: * array.c (rb_ary_flatten): flatten(0) works as Array#dup. [ruby-core:23168] * test/ruby/test_array.rb: add a test for above. Modified files: trunk/ChangeLog trunk/array.c trunk/test/ruby/test_array.rb Index: array.c =================================================================== --- array.c (revision 23190) +++ array.c (revision 23191) @@ -648,6 +648,12 @@ } } +static VALUE +ary_make_shared_copy(VALUE ary) +{ + return ary_make_partial(ary, rb_obj_class(ary), 0, RARRAY_LEN(ary)); +} + enum ary_take_pos_flags { ARY_TAKE_FIRST = 0, @@ -3360,7 +3366,7 @@ rb_scan_args(argc, argv, "01", &lv); if (!NIL_P(lv)) level = NUM2INT(lv); - if (level == 0) return ary; + if (level == 0) return ary_make_shared_copy(ary); result = flatten(ary, level, &mod); OBJ_INFECT(result, ary); Index: ChangeLog =================================================================== --- ChangeLog (revision 23190) +++ ChangeLog (revision 23191) @@ -1,3 +1,10 @@ +Wed Apr 15 20:24:49 2009 Yusuke Endoh <mame@t...> + + * array.c (rb_ary_flatten): flatten(0) works as Array#dup. + [ruby-core:23168] + + * test/ruby/test_array.rb: add a test for above. + Wed Apr 15 11:53:35 2009 NARUSE, Yui <naruse@r...> * dir.c (fnmatch_helper): use rb_enc_precise_mbclen and Index: test/ruby/test_array.rb =================================================================== --- test/ruby/test_array.rb (revision 23190) +++ test/ruby/test_array.rb (revision 23191) @@ -719,6 +719,11 @@ a7 = a6.flatten assert_equal(true, a7.tainted?) assert_equal(true, a7.untrusted?) + + a8 = @cls[[1, 2], 3] + a9 = a8.flatten(0) + assert_equal(a8, a9) + assert_not_same(a8, a9) end def test_flatten! -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/