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

ruby-changes:31787

From: tmm1 <ko1@a...>
Date: Wed, 27 Nov 2013 08:30:32 +0900 (JST)
Subject: [ruby-changes:31787] tmm1:r43866 (trunk): * compile.c: Use rb_fstring() to de-duplicate string literals in code. [Bug #9159]

tmm1	2013-11-27 08:30:25 +0900 (Wed, 27 Nov 2013)

  New Revision: 43866

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

  Log:
    * compile.c: Use rb_fstring() to de-duplicate string literals in code.  [ruby-core:58599] [Bug #9159] [ruby-core:54405]
    * iseq.c (prepare_iseq_build): De-duplicate iseq labels and source locations.
    * re.c (rb_reg_initialize): Use rb_fstring() for regex string.
    * string.c (rb_fstring): Handle non-string and already-fstr arguments.
    * vm_eval.c (eval_string_with_cref): De-duplicate eval source filename.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/iseq.c
    trunk/re.c
    trunk/string.c
    trunk/vm_eval.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 43865)
+++ ChangeLog	(revision 43866)
@@ -1,3 +1,14 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Nov 27 08:24:49 2013  Aman Gupta <ruby@t...>
+
+	* compile.c: Use rb_fstring() to de-duplicate string literals in code.
+	  [ruby-core:58599] [Bug #9159] [ruby-core:54405]
+	* iseq.c (prepare_iseq_build): De-duplicate iseq labels and source
+	  locations.
+	* re.c (rb_reg_initialize): Use rb_fstring() for regex string.
+	* string.c (rb_fstring): Handle non-string and already-fstr arguments.
+	* vm_eval.c (eval_string_with_cref): De-duplicate eval source
+	  filename.
+
 Wed Nov 27 07:13:54 2013  Aaron Patterson <aaron@t...>
 
 	* ext/psych/lib/psych.rb: psych version 2.0.2
Index: re.c
===================================================================
--- re.c	(revision 43865)
+++ re.c	(revision 43866)
@@ -2460,8 +2460,7 @@ rb_reg_initialize(VALUE obj, const char https://github.com/ruby/ruby/blob/trunk/re.c#L2460
 			  options & ARG_REG_OPTION_MASK, err,
 			  sourcefile, sourceline);
     if (!re->ptr) return -1;
-    OBJ_WRITE(obj, &re->src, rb_enc_str_new(s, len, enc));
-    OBJ_FREEZE(re->src);
+    OBJ_WRITE(obj, &re->src, rb_fstring(rb_enc_str_new(s, len, enc)));
     RB_GC_GUARD(unescaped);
     return 0;
 }
Index: iseq.c
===================================================================
--- iseq.c	(revision 43865)
+++ iseq.c	(revision 43866)
@@ -264,8 +264,10 @@ prepare_iseq_build(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/iseq.c#L264
     OBJ_WRITE(iseq->self, &iseq->klass, 0);
     set_relation(iseq, parent);
 
-    OBJ_FREEZE(name);
-    OBJ_FREEZE(path);
+    name = rb_fstring(name);
+    path = rb_fstring(path);
+    if (RTEST(absolute_path))
+	absolute_path = rb_fstring(absolute_path);
 
     iseq_location_setup(iseq, path, absolute_path, name, first_lineno);
     if (iseq != iseq->local_iseq) {
Index: string.c
===================================================================
--- string.c	(revision 43865)
+++ string.c	(revision 43866)
@@ -136,6 +136,11 @@ VALUE https://github.com/ruby/ruby/blob/trunk/string.c#L136
 rb_fstring(VALUE str)
 {
     st_data_t fstr;
+    Check_Type(str, T_STRING);
+
+    if (FL_TEST(str, RSTRING_FSTR))
+	return str;
+
     if (st_lookup(frozen_strings, (st_data_t)str, &fstr)) {
 	str = (VALUE)fstr;
 	/* because of lazy sweep, str may be unmaked already and swept
Index: compile.c
===================================================================
--- compile.c	(revision 43865)
+++ compile.c	(revision 43866)
@@ -171,10 +171,10 @@ r_value(VALUE value) https://github.com/ruby/ruby/blob/trunk/compile.c#L171
   (((rb_iseq_t*)DATA_PTR(iseq))->location.absolute_path)
 
 #define NEW_ISEQVAL(node, name, type, line_no)       \
-  new_child_iseq(iseq, (node), (name), 0, (type), (line_no))
+  new_child_iseq(iseq, (node), rb_fstring(name), 0, (type), (line_no))
 
 #define NEW_CHILD_ISEQVAL(node, name, type, line_no)       \
-  new_child_iseq(iseq, (node), (name), iseq->self, (type), (line_no))
+  new_child_iseq(iseq, (node), rb_fstring(name), iseq->self, (type), (line_no))
 
 /* add instructions */
 #define ADD_SEQ(seq1, seq2) \
@@ -2254,15 +2254,16 @@ compile_dstr_fragments(rb_iseq_t *iseq, https://github.com/ruby/ruby/blob/trunk/compile.c#L2254
 
     debugp_param("nd_lit", lit);
     if (!NIL_P(lit)) {
-	hide_obj(lit);
 	cnt++;
+	if (RB_TYPE_P(lit, T_STRING))
+	    lit = node->nd_lit = rb_fstring(node->nd_lit);
 	ADD_INSN1(ret, nd_line(node), putobject, lit);
     }
 
     while (list) {
 	node = list->nd_head;
 	if (nd_type(node) == NODE_STR) {
-	    hide_obj(node->nd_lit);
+	    node->nd_lit = rb_fstring(node->nd_lit);
 	    ADD_INSN1(ret, nd_line(node), putobject, node->nd_lit);
 	}
 	else {
@@ -2515,7 +2516,7 @@ case_when_optimizable_literal(NODE * nod https://github.com/ruby/ruby/blob/trunk/compile.c#L2516
 	break;
       }
       case NODE_STR:
-	return node->nd_lit;
+	return node->nd_lit = rb_fstring(node->nd_lit);
     }
     return Qundef;
 }
@@ -2542,8 +2543,8 @@ when_vals(rb_iseq_t *iseq, LINK_ANCHOR * https://github.com/ruby/ruby/blob/trunk/compile.c#L2543
 	ADD_INSN(cond_seq, nd_line(val), dup); /* dup target */
 
 	if (nd_type(val) == NODE_STR) {
+	    val->nd_lit = rb_fstring(val->nd_lit);
 	    debugp_param("nd_lit", val->nd_lit);
-	    OBJ_FREEZE(val->nd_lit);
 	    ADD_INSN1(cond_seq, nd_line(val), putobject, val->nd_lit);
 	}
 	else {
@@ -4798,9 +4799,9 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4799
 	break;
       }
       case NODE_STR:{
+	node->nd_lit = rb_fstring(node->nd_lit);
 	debugp_param("nd_lit", node->nd_lit);
 	if (!poped) {
-	    OBJ_FREEZE(node->nd_lit);
 	    ADD_INSN1(ret, line, putstring, node->nd_lit);
 	}
 	break;
@@ -4814,7 +4815,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4815
 	break;
       }
       case NODE_XSTR:{
-	OBJ_FREEZE(node->nd_lit);
+	node->nd_lit = rb_fstring(node->nd_lit);
 	ADD_CALL_RECEIVER(ret, line);
 	ADD_INSN1(ret, line, putobject, node->nd_lit);
 	ADD_CALL(ret, line, ID2SYM(idBackquote), INT2FIX(1));
@@ -4908,7 +4909,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4909
       }
       case NODE_DEFN:{
 	VALUE iseqval = NEW_ISEQVAL(node->nd_defn,
-				    rb_str_dup(rb_id2str(node->nd_mid)),
+				    rb_id2str(node->nd_mid),
 				    ISEQ_TYPE_METHOD, line);
 
 	debugp_param("defn/iseq", iseqval);
@@ -4928,7 +4929,7 @@ iseq_compile_each(rb_iseq_t *iseq, LINK_ https://github.com/ruby/ruby/blob/trunk/compile.c#L4929
       }
       case NODE_DEFS:{
 	VALUE iseqval = NEW_ISEQVAL(node->nd_defn,
-				    rb_str_dup(rb_id2str(node->nd_mid)),
+				    rb_id2str(node->nd_mid),
 				    ISEQ_TYPE_METHOD, line);
 
 	debugp_param("defs/iseq", iseqval);
@@ -5530,7 +5531,7 @@ rb_insns_name_array(void) https://github.com/ruby/ruby/blob/trunk/compile.c#L5531
     VALUE ary = rb_ary_new();
     int i;
     for (i = 0; i < numberof(insn_name_info); i++) {
-	rb_ary_push(ary, rb_obj_freeze(rb_str_new2(insn_name_info[i])));
+	rb_ary_push(ary, rb_fstring(rb_str_new2(insn_name_info[i])));
     }
     return rb_obj_freeze(ary);
 }
Index: vm_eval.c
===================================================================
--- vm_eval.c	(revision 43865)
+++ vm_eval.c	(revision 43866)
@@ -1239,6 +1239,11 @@ eval_string_with_cref(VALUE self, VALUE https://github.com/ruby/ruby/blob/trunk/vm_eval.c#L1239
 	    fname = rb_usascii_str_new_cstr("(eval)");
 	}
 
+	if (RTEST(fname))
+	    fname = rb_fstring(fname);
+	if (RTEST(absolute_path))
+	    absolute_path = rb_fstring(absolute_path);
+
 	/* make eval iseq */
 	th->parse_in_eval++;
 	th->mild_compile_error++;

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

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