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

ruby-changes:12509

From: nobu <ko1@a...>
Date: Mon, 20 Jul 2009 19:01:23 +0900 (JST)
Subject: [ruby-changes:12509] Ruby:r24212 (trunk): * compile.c (compile_dstr_fragments): reduced needless literal.

nobu	2009-07-20 19:01:05 +0900 (Mon, 20 Jul 2009)

  New Revision: 24212

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

  Log:
    * compile.c (compile_dstr_fragments): reduced needless literal.
    * parse.y (xstring, regexp, dsym, literal_concat, evstr2dstr):
      literal at the top of dstr is no longer needed if it is empty,
      since concatstrings and toregexp always create new strings.

  Modified files:
    trunk/ChangeLog
    trunk/compile.c
    trunk/parse.y
    trunk/test/ruby/test_literal.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 24211)
+++ ChangeLog	(revision 24212)
@@ -1,3 +1,11 @@
+Mon Jul 20 19:00:58 2009  Nobuyoshi Nakada  <nobu@r...>
+
+	* compile.c (compile_dstr_fragments): reduced needless literal.
+
+	* parse.y (xstring, regexp, dsym, literal_concat, evstr2dstr):
+	  literal at the top of dstr is no longer needed if it is empty,
+	  since concatstrings and toregexp always create new strings.
+
 Mon Jul 20 12:51:39 2009  wanabe  <s.wanabe@g...>
 
 	* lib/matrix.rb (Matrix#rank): revert a part of r20859 to avoid
@@ -27,7 +35,7 @@
 
 Sun Jul 19 17:32:37 2009  Nobuyoshi Nakada  <nobu@r...>
 
-	* io.c (io_read): should taint the result.   [ruby-dev:38826]
+	* io.c (io_read): should taint the result.  [ruby-dev:38826]
 
 Sun Jul 19 11:00:14 2009  Nobuyoshi Nakada  <nobu@r...>
 
Index: compile.c
===================================================================
--- compile.c	(revision 24211)
+++ compile.c	(revision 24212)
@@ -2143,11 +2143,14 @@
 {
     NODE *list = node->nd_next;
     VALUE lit = node->nd_lit;
-    int cnt = 1;
+    int cnt = 0;
 
     debugp_param("nd_lit", lit);
-    hide_obj(lit);
-    ADD_INSN1(ret, nd_line(node), putobject, lit);
+    if (!NIL_P(lit)) {
+	hide_obj(lit);
+	cnt++;
+	ADD_INSN1(ret, nd_line(node), putobject, lit);
+    }
 
     while (list) {
 	COMPILE(ret, "each string", list->nd_head);
Index: parse.y
===================================================================
--- parse.y	(revision 24211)
+++ parse.y	(revision 24212)
@@ -3806,7 +3806,7 @@
 				nd_set_type(node, NODE_DXSTR);
 				break;
 			      default:
-				node = NEW_NODE(NODE_DXSTR, STR_NEW0(), 1, NEW_LIST(node));
+				node = NEW_NODE(NODE_DXSTR, Qnil, 1, NEW_LIST(node));
 				break;
 			    }
 			}
@@ -3835,7 +3835,7 @@
 			    }
 			    break;
 			  default:
-			    node = NEW_NODE(NODE_DSTR, STR_NEW0(), 1, NEW_LIST(node));
+			    node = NEW_NODE(NODE_DSTR, Qnil, 1, NEW_LIST(node));
 			  case NODE_DSTR:
 			    if (options & RE_OPTION_ONCE) {
 				nd_set_type(node, NODE_DREGX_ONCE);
@@ -3844,7 +3844,7 @@
 				nd_set_type(node, NODE_DREGX);
 			    }
 			    node->nd_cflag = options & RE_OPTION_MASK;
-                            reg_fragment_check(node->nd_lit, options);
+			    if (!NIL_P(node->nd_lit)) reg_fragment_check(node->nd_lit, options);
                             for (list = node->nd_next; list; list = list->nd_next) {
                                 if (nd_type(list->nd_head) == NODE_STR) {
                                     reg_fragment_check(list->nd_head->nd_lit, options);
@@ -4081,7 +4081,7 @@
 				nd_set_type($$, NODE_LIT);
 				break;
 			      default:
-				$$ = NEW_NODE(NODE_DSYM, STR_NEW0(), 1, NEW_LIST($$));
+				$$ = NEW_NODE(NODE_DSYM, Qnil, 1, NEW_LIST($$));
 				break;
 			    }
 			}
@@ -7809,7 +7809,7 @@
 
     htype = nd_type(head);
     if (htype == NODE_EVSTR) {
-	NODE *node = NEW_DSTR(STR_NEW0());
+	NODE *node = NEW_DSTR(Qnil);
 	head = list_append(node, head);
     }
     switch (nd_type(tail)) {
@@ -7858,7 +7858,7 @@
 evstr2dstr_gen(struct parser_params *parser, NODE *node)
 {
     if (nd_type(node) == NODE_EVSTR) {
-	node = list_append(NEW_DSTR(STR_NEW0()), node);
+	node = list_append(NEW_DSTR(Qnil), node);
     }
     return node;
 }
Index: test/ruby/test_literal.rb
===================================================================
--- test/ruby/test_literal.rb	(revision 24211)
+++ test/ruby/test_literal.rb	(revision 24212)
@@ -59,6 +59,10 @@
     assert_equal '16', "#{2 ** 4}"
     s = "string"
     assert_equal s, "#{s}"
+    a = 'Foo'
+    b = "#{a}" << 'Bar'
+    assert_equal('Foo', a, 'r3842')
+    assert_equal('FooBar', b, 'r3842')
   end
 
   def test_dsymbol

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

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