1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* array.c (rb_ary_flatten): flatten(0) works as Array#dup.

[ruby-core:23168]

* test/ruby/test_array.rb: add a test for above.


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23191 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
mame 2009-04-15 11:47:54 +00:00
parent 31c1883a54
commit bded3bb726
3 changed files with 19 additions and 1 deletions

View file

@ -1,3 +1,10 @@
Wed Apr 15 20:24:49 2009 Yusuke Endoh <mame@tsg.ne.jp>
* 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@ruby-lang.org> Wed Apr 15 11:53:35 2009 NARUSE, Yui <naruse@ruby-lang.org>
* dir.c (fnmatch_helper): use rb_enc_precise_mbclen and * dir.c (fnmatch_helper): use rb_enc_precise_mbclen and

View file

@ -648,6 +648,12 @@ ary_make_partial(VALUE ary, VALUE klass, long offset, long len)
} }
} }
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 enum ary_take_pos_flags
{ {
ARY_TAKE_FIRST = 0, ARY_TAKE_FIRST = 0,
@ -3360,7 +3366,7 @@ rb_ary_flatten(int argc, VALUE *argv, VALUE ary)
rb_scan_args(argc, argv, "01", &lv); rb_scan_args(argc, argv, "01", &lv);
if (!NIL_P(lv)) level = NUM2INT(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); result = flatten(ary, level, &mod);
OBJ_INFECT(result, ary); OBJ_INFECT(result, ary);

View file

@ -719,6 +719,11 @@ class TestArray < Test::Unit::TestCase
a7 = a6.flatten a7 = a6.flatten
assert_equal(true, a7.tainted?) assert_equal(true, a7.tainted?)
assert_equal(true, a7.untrusted?) assert_equal(true, a7.untrusted?)
a8 = @cls[[1, 2], 3]
a9 = a8.flatten(0)
assert_equal(a8, a9)
assert_not_same(a8, a9)
end end
def test_flatten! def test_flatten!