[前][次][番号順一覧][スレッド一覧]

ruby-changes:45755

From: normal <ko1@a...>
Date: Sat, 11 Mar 2017 05:09:12 +0900 (JST)
Subject: [ruby-changes:45755] normal:r57828 (trunk): compile.c: apply opt_str_freeze to String#-@ (uminus)

normal	2017-03-11 05:09:06 +0900 (Sat, 11 Mar 2017)

  New Revision: 57828

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=57828

  Log:
    compile.c: apply opt_str_freeze to String#-@ (uminus)
    
    The same optimization used for "literal string".freeze
    can easily apply to uminus without introducing any
    compatibility problems.

  Modified files:
    trunk/bootstraptest/test_insns.rb
    trunk/compile.c
Index: bootstraptest/test_insns.rb
===================================================================
--- bootstraptest/test_insns.rb	(revision 57827)
+++ bootstraptest/test_insns.rb	(revision 57828)
@@ -178,6 +178,7 @@ tests = [ https://github.com/ruby/ruby/blob/trunk/bootstraptest/test_insns.rb#L178
   },
 
   [ 'opt_str_freeze', %q{ 'true'.freeze }, ],
+  [ 'opt_str_freeze', %q{ -'true' }, ],
   [ 'opt_str_freeze', <<~'},', ], # {
     class String
       def freeze
Index: compile.c
===================================================================
--- compile.c	(revision 57827)
+++ compile.c	(revision 57828)
@@ -5188,7 +5188,8 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L5188
 	 *   "literal".freeze -> opt_str_freeze("literal")
 	 */
 	if (node->nd_recv && nd_type(node->nd_recv) == NODE_STR &&
-	    node->nd_mid == idFreeze && node->nd_args == NULL &&
+	    (node->nd_mid == idFreeze || node->nd_mid == idUMinus) &&
+	    node->nd_args == NULL &&
 	    ISEQ_COMPILE_DATA(iseq)->current_block == NULL &&
 	    ISEQ_COMPILE_DATA(iseq)->option->specialized_instruction) {
 	    VALUE str = rb_fstring(node->nd_recv->nd_lit);

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]