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

ruby-changes:42416

From: nobu <ko1@a...>
Date: Tue, 5 Apr 2016 16:18:46 +0900 (JST)
Subject: [ruby-changes:42416] nobu:r54490 (trunk): string.c: rb_str_concat_literals

nobu	2016-04-05 17:15:22 +0900 (Tue, 05 Apr 2016)

  New Revision: 54490

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

  Log:
    string.c: rb_str_concat_literals
    
    * string.c (rb_str_concat_literals): concatenate literal string
      fragments.

  Modified files:
    trunk/insns.def
    trunk/string.c
    trunk/vm.c
Index: vm.c
===================================================================
--- vm.c	(revision 54489)
+++ vm.c	(revision 54490)
@@ -23,7 +23,7 @@ https://github.com/ruby/ruby/blob/trunk/vm.c#L23
 #include "probes.h"
 #include "probes_helper.h"
 
-VALUE rb_str_append_literal(VALUE str, VALUE str2);
+VALUE rb_str_concat_literals(size_t, const VALUE*);
 
 static inline VALUE *
 VM_EP_LEP(VALUE *ep)
Index: string.c
===================================================================
--- string.c	(revision 54489)
+++ string.c	(revision 54490)
@@ -2677,13 +2677,24 @@ rb_str_append(VALUE str, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2677
 }
 
 VALUE
-rb_str_append_literal(VALUE str, VALUE str2)
+rb_str_concat_literals(size_t num, const VALUE *strary)
 {
-    int encidx = rb_enc_get_index(str2);
-    rb_str_buf_append(str, str2);
-    if (encidx != ENCINDEX_US_ASCII) {
-	if (rb_enc_get_index(str) == ENCINDEX_US_ASCII)
-	    rb_enc_associate_index(str, encidx);
+    VALUE str;
+    size_t i;
+
+    if (!num) return rb_str_new(0, 0);
+    str = rb_str_resurrect(strary[0]);
+    for (i = 1; i < num; ++i) {
+	const VALUE v = strary[i];
+	int encidx = ENCODING_GET(v);
+
+	rb_enc_cr_str_buf_cat(str, RSTRING_PTR(v), RSTRING_LEN(v),
+			      encidx, ENC_CODERANGE(v), NULL);
+	OBJ_INFECT_RAW(str, v);
+	if (encidx != ENCINDEX_US_ASCII) {
+	    if (ENCODING_GET_INLINED(str) == ENCINDEX_US_ASCII)
+		rb_enc_set_index(str, encidx);
+	}
     }
     return str;
 }
Index: insns.def
===================================================================
--- insns.def	(revision 54489)
+++ insns.def	(revision 54490)
@@ -365,13 +365,7 @@ concatstrings https://github.com/ruby/ruby/blob/trunk/insns.def#L365
 (...)
 (VALUE val) // inc += 1 - num;
 {
-    rb_num_t i = num - 1;
-
-    val = rb_str_resurrect(TOPN(i));
-    while (i-- > 0) {
-	const VALUE v = TOPN(i);
-	rb_str_append_literal(val, v);
-    }
+    val = rb_str_concat_literals(num, &TOPN(num-1));
     POPN(num);
 }
 

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

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