diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-15 20:41:38 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-15 20:41:38 +0000 |
commit | fde3c421bea8bd514acddb4c1b2d5f81afd1af36 (patch) | |
tree | 175471344dc9be9ccaabf8ef1f7dcf2998edfe49 | |
parent | e315f8471d2c2fbe3c5d96a9bf8d987fe5786f3b (diff) | |
download | ruby-fde3c421bea8bd514acddb4c1b2d5f81afd1af36.tar.gz |
* insns.def (splatarray): make new array if flag is set.
* compile.c (iseq_compile_each): make new array with
splat. [ruby-core:21901][Feature #1125]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34633 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 7 | ||||
-rw-r--r-- | compile.c | 2 | ||||
-rw-r--r-- | insns.def | 3 | ||||
-rw-r--r-- | test/ruby/test_basicinstructions.rb | 7 |
4 files changed, 17 insertions, 2 deletions
@@ -1,3 +1,10 @@ +Thu Feb 16 05:41:35 2012 Nobuyoshi Nakada <nobu@ruby-lang.org> + + * insns.def (splatarray): make new array if flag is set. + + * compile.c (iseq_compile_each): make new array with + splat. [ruby-core:21901][Feature #1125] + Thu Feb 16 00:14:04 2012 Kazuhiro NISHIYAMA <zn@mbf.nifty.com> * lib/abbrev.rb (Array#abbrev): add missing '"' in documentation. @@ -4643,7 +4643,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ANCHOR *ret, NODE * node, int poped) } case NODE_SPLAT:{ COMPILE(ret, "splat", node->nd_head); - ADD_INSN1(ret, nd_line(node), splatarray, Qfalse); + ADD_INSN1(ret, nd_line(node), splatarray, Qtrue); if (poped) { ADD_INSN(ret, nd_line(node), pop); @@ -533,6 +533,9 @@ splatarray if (NIL_P(tmp)) { tmp = rb_ary_new3(1, ary); } + else if (RTEST(flag)) { + tmp = rb_ary_dup(tmp); + } obj = tmp; } diff --git a/test/ruby/test_basicinstructions.rb b/test/ruby/test_basicinstructions.rb index ff14e4a7a6..7e57530d72 100644 --- a/test/ruby/test_basicinstructions.rb +++ b/test/ruby/test_basicinstructions.rb @@ -632,7 +632,7 @@ class TestBasicInstructions < Test::Unit::TestCase assert_equal 'i', $~[9] assert_equal 'x', $` assert_equal 'abcdefghi', $& - assert_equal 'y', $' + assert_equal "y", $' assert_equal 'i', $+ assert_equal 'a', $1 assert_equal 'b', $2 @@ -662,15 +662,20 @@ class TestBasicInstructions < Test::Unit::TestCase end def test_array_splat + feature1125 = '[ruby-core:21901]' + a = [] assert_equal [], [*a] assert_equal [1], [1, *a] + assert_not_same(a, [*a], feature1125) a = [2] assert_equal [2], [*a] assert_equal [1, 2], [1, *a] + assert_not_same(a, [*a], feature1125) a = [2, 3] assert_equal [2, 3], [*a] assert_equal [1, 2, 3], [1, *a] + assert_not_same(a, [*a], feature1125) a = nil assert_equal [], [*a] |