From 669a55dfed5cc6e32afee69694b95e8b4c187f54 Mon Sep 17 00:00:00 2001 From: normal Date: Mon, 27 Mar 2017 06:12:37 +0000 Subject: fix redefinition optimization for -"literal string" (UMinus) Unfortunately this enlarges insns.def by yet another instruction. However, it is much prettier than opt_str_freeze in use, and maybe we can avoid having so many instructions in the future. [ruby-core:80368] * insns.def (DEFINE_INSN): new instruction: opt_str_uminus (maybe temporary) * compile.c (iseq_compile_each0): split instructions * test/ruby/test_optimization.rb (test_string_uminus): new test * vm.c (vm_init_redefined_flag): set redefinintion flag for uminus * vm_core.h (enum ruby_basic_operators): add BOP_UMINUS git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58144 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- compile.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'compile.c') diff --git a/compile.c b/compile.c index e3d66b6809..317475b525 100644 --- a/compile.c +++ b/compile.c @@ -5211,7 +5211,12 @@ iseq_compile_each0(rb_iseq_t *iseq, LINK_ANCHOR *const ret, NODE *node, int popp ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) { VALUE str = rb_fstring(node->nd_recv->nd_lit); iseq_add_mark_object(iseq, str); - ADD_INSN1(ret, line, opt_str_freeze, str); + if (node->nd_mid == idUMinus) { + ADD_INSN1(ret, line, opt_str_uminus, str); + } + else { + ADD_INSN1(ret, line, opt_str_freeze, str); + } if (popped) { ADD_INSN(ret, line, pop); } -- cgit v1.2.3