ruby-changes:50215
From: nobu <ko1@a...>
Date: Fri, 9 Feb 2018 23:10:08 +0900 (JST)
Subject: [ruby-changes:50215] nobu:r62333 (trunk): compile.c: popped hash
nobu 2018-02-09 23:09:58 +0900 (Fri, 09 Feb 2018) New Revision: 62333 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=62333 Log: compile.c: popped hash * compile.c (compile_array): skip creating new hash if preceeding elements are popped all. [ruby-core:85486] [Bug #14459] Modified files: trunk/compile.c trunk/test/ruby/test_optimization.rb Index: compile.c =================================================================== --- compile.c (revision 62332) +++ compile.c (revision 62333) @@ -3761,14 +3761,20 @@ compile_array(rb_iseq_t *iseq, LINK_ANCH https://github.com/ruby/ruby/blob/trunk/compile.c#L3761 case COMPILE_ARRAY_TYPE_HASH: if (i > 0) { if (first) { - ADD_INSN1(anchor, line, newhash, INT2FIX(i)); + if (!popped) { + ADD_INSN1(anchor, line, newhash, INT2FIX(i)); + } APPEND_LIST(ret, anchor); } else { - ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); - ADD_INSN(ret, line, swap); + if (!popped) { + ADD_INSN1(ret, line, putspecialobject, INT2FIX(VM_SPECIAL_OBJECT_VMCORE)); + ADD_INSN(ret, line, swap); + } APPEND_LIST(ret, anchor); - ADD_SEND(ret, line, id_core_hash_merge_ptr, INT2FIX(i + 1)); + if (!popped) { + ADD_SEND(ret, line, id_core_hash_merge_ptr, INT2FIX(i + 1)); + } } } if (kw) { Index: test/ruby/test_optimization.rb =================================================================== --- test/ruby/test_optimization.rb (revision 62332) +++ test/ruby/test_optimization.rb (revision 62333) @@ -709,6 +709,11 @@ class TestRubyOptimization < Test::Unit: https://github.com/ruby/ruby/blob/trunk/test/ruby/test_optimization.rb#L709 bug = '[ruby-core:84340] [Bug #14201]' eval("{**(bug = nil; {})};42") assert_nil(bug) + + bug = '[ruby-core:85486] [Bug #14459]' + h = {} + assert_equal(bug, eval('{ok: 42, **h}; bug')) + assert_equal(:ok, eval('{ok: bug = :ok, **h}; bug')) end def test_overwritten_blockparam -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/