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

ruby-changes:31548

From: charliesome <ko1@a...>
Date: Sun, 10 Nov 2013 06:17:14 +0900 (JST)
Subject: [ruby-changes:31548] charliesome:r43627 (trunk): * compile.c (iseq_compile_each): emit opt_str_freeze if the #freeze

charliesome	2013-11-10 06:17:06 +0900 (Sun, 10 Nov 2013)

  New Revision: 43627

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=43627

  Log:
    * compile.c (iseq_compile_each): emit opt_str_freeze if the #freeze
      method is called on a static string literal with no arguments.
    
    * defs/id.def (firstline): add freeze so idFreeze is available
    
    * insns.def (opt_str_freeze): add opt_str_freeze instruction which
      pushes a frozen string literal without allocating a new object if
      String#freeze is not overriden
    
    * string.c (Init_String): define String#freeze
    
    * vm.c (vm_init_redefined_flag): define BOP_FREEZE on String class as
      a basic operation
    
    * vm_insnhelper.h: ditto

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/defs/id.def
    trunk/insns.def
    trunk/string.c
    trunk/vm.c
    trunk/vm_insnhelper.h
Index: defs/id.def
===================================================================
--- defs/id.def	(revision 43626)
+++ defs/id.def	(revision 43627)
@@ -1,5 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/defs/id.def#L1
 # -*- mode: ruby; coding: us-ascii -*-
 firstline, predefined = __LINE__+1, %[\
+  freeze
   inspect
   intern
   object_id
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43626)
+++ ChangeLog	(revision 43627)
@@ -1,3 +1,23 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Nov 10 06:14:39 2013  Charlie Somerville  <charliesome@r...>
+
+	* compile.c (iseq_compile_each): emit opt_str_freeze if the #freeze
+	  method is called on a static string literal with no arguments.
+
+	* defs/id.def (firstline): add freeze so idFreeze is available
+
+	* insns.def (opt_str_freeze): add opt_str_freeze instruction which
+	  pushes a frozen string literal without allocating a new object if
+	  String#freeze is not overriden
+
+	* string.c (Init_String): define String#freeze
+
+	* vm.c (vm_init_redefined_flag): define BOP_FREEZE on String class as
+	  a basic operation
+	
+	* vm_insnhelper.h: ditto
+
+	[Feature #8992] [ruby-core:57705]
+
 Sun Nov 10 01:34:14 2013  Koichi Sasada  <ko1@a...>
 
 	* gc.c (vm_malloc_increase): sweep immediately on GC due to malloc().
Index: insns.def
===================================================================
--- insns.def	(revision 43626)
+++ insns.def	(revision 43627)
@@ -999,6 +999,20 @@ send https://github.com/ruby/ruby/blob/trunk/insns.def#L999
     CALL_METHOD(ci);
 }
 
+DEFINE_INSN
+opt_str_freeze
+(VALUE str)
+()
+(VALUE val)
+{
+    if (BASIC_OP_UNREDEFINED_P(BOP_FREEZE, STRING_REDEFINED_OP_FLAG)) {
+	val = str;
+    }
+    else {
+	val = rb_funcall(rb_str_resurrect(str), idFreeze, 0);
+    }
+}
+
 /**
   @c optimize
   @e Invoke method without block, splat
Index: string.c
===================================================================
--- string.c	(revision 43626)
+++ string.c	(revision 43627)
@@ -8745,6 +8745,7 @@ Init_String(void) https://github.com/ruby/ruby/blob/trunk/string.c#L8745
     rb_define_method(rb_cString, "byteslice", rb_str_byteslice, -1);
     rb_define_method(rb_cString, "scrub", str_scrub, -1);
     rb_define_method(rb_cString, "scrub!", str_scrub_bang, -1);
+    rb_define_method(rb_cString, "freeze", rb_obj_freeze, 0);
 
     rb_define_method(rb_cString, "to_i", rb_str_to_i, -1);
     rb_define_method(rb_cString, "to_f", rb_str_to_f, 0);
Index: compile.c
===================================================================
--- compile.c	(revision 43626)
+++ compile.c	(revision 43627)
@@ -4314,6 +4314,17 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4314
 	break;
       }
       case NODE_CALL:
+	if (node->nd_recv && nd_type(node->nd_recv) == NODE_STR &&
+	    node->nd_mid == idFreeze && node->nd_args == NULL)
+	{
+	    VALUE str = rb_fstring(node->nd_recv->nd_lit);
+	    iseq_add_mark_object(iseq, str);
+	    ADD_INSN1(ret, line, opt_str_freeze, str);
+	    if (poped) {
+		ADD_INSN(ret, line, pop);
+	    }
+	    break;
+	}
       case NODE_FCALL:
       case NODE_VCALL:{		/* VCALL: variable or call */
 	/*
Index: vm.c
===================================================================
--- vm.c	(revision 43626)
+++ vm.c	(revision 43627)
@@ -1082,6 +1082,7 @@ vm_init_redefined_flag(void) https://github.com/ruby/ruby/blob/trunk/vm.c#L1082
     OP(EmptyP, EMPTY_P), (C(Array), C(String), C(Hash));
     OP(Succ, SUCC), (C(Fixnum), C(String), C(Time));
     OP(EqTilde, MATCH), (C(Regexp), C(String));
+    OP(Freeze, FREEZE), (C(String));
 #undef C
 #undef OP
 }
Index: vm_insnhelper.h
===================================================================
--- vm_insnhelper.h	(revision 43626)
+++ vm_insnhelper.h	(revision 43627)
@@ -56,6 +56,7 @@ enum { https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.h#L56
   BOP_NOT,
   BOP_NEQ,
   BOP_MATCH,
+  BOP_FREEZE,
 
   BOP_LAST_
 };

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

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