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

ruby-changes:29668

From: nobu <ko1@a...>
Date: Mon, 1 Jul 2013 15:04:46 +0900 (JST)
Subject: [ruby-changes:29668] nobu:r41720 (trunk): string.c: coderange appending to empty string

nobu	2013-07-01 15:03:45 +0900 (Mon, 01 Jul 2013)

  New Revision: 41720

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

  Log:
    string.c: coderange appending to empty string
    
    * string.c (rb_enc_cr_str_buf_cat, rb_str_append): consider an empty
      string 7bit-clean and should not discard cached coderange of string
      to be appended.

  Modified files:
    trunk/ChangeLog
    trunk/string.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41719)
+++ ChangeLog	(revision 41720)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jul  1 15:03:42 2013  Nobuyoshi Nakada  <nobu@r...>
+
+	* string.c (rb_enc_cr_str_buf_cat, rb_str_append): consider an empty
+	  string 7bit-clean and should not discard cached coderange of string
+	  to be appended.
+
 Mon Jul  1 12:56:41 2013  Shugo Maeda  <shugo@r...>
 
 	* eval.c (rb_using_module): activate refinements in the ancestors of
Index: string.c
===================================================================
--- string.c	(revision 41719)
+++ string.c	(revision 41720)
@@ -1958,7 +1958,7 @@ rb_enc_cr_str_buf_cat(VALUE str, const c https://github.com/ruby/ruby/blob/trunk/string.c#L1958
     int res_encindex;
     int str_cr, res_cr;
 
-    str_cr = ENC_CODERANGE(str);
+    str_cr = RSTRING_LEN(str) ? ENC_CODERANGE(str) : ENC_CODERANGE_7BIT;
 
     if (str_encindex == ptr_encindex) {
         if (str_cr == ENC_CODERANGE_UNKNOWN)
@@ -2095,7 +2095,8 @@ rb_str_append(VALUE str, VALUE str2) https://github.com/ruby/ruby/blob/trunk/string.c#L2095
         long len = RSTRING_LEN(str) + len2;
         enc = rb_enc_check(str, str2);
         cr = ENC_CODERANGE(str);
-        if ((cr2 = ENC_CODERANGE(str2)) > cr) cr = cr2;
+        if ((cr2 = ENC_CODERANGE(str2)) > cr || RSTRING_LEN(str) == 0)
+	    cr = cr2;
         rb_str_modify_expand(str, len2);
         memcpy(RSTRING(str)->as.heap.ptr + RSTRING(str)->as.heap.len,
                RSTRING_PTR(str2), len2+1);

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

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