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

ruby-changes:33537

From: naruse <ko1@a...>
Date: Fri, 18 Apr 2014 15:43:18 +0900 (JST)
Subject: [ruby-changes:33537] naruse:r45618 (trunk): * string.c (str_strlen): use enc_strlen if the coderange is known.

naruse	2014-04-18 15:43:08 +0900 (Fri, 18 Apr 2014)

  New Revision: 45618

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

  Log:
    * string.c (str_strlen): use enc_strlen if the coderange is known.

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 45617)
+++ ChangeLog	(revision 45618)
@@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri Apr 18 14:32:40 2014  NARUSE, Yui  <naruse@r...>
+
+	* string.c (str_strlen): use enc_strlen if the coderange is known.
+
 Fri Apr 18 14:21:21 2014  NARUSE, Yui  <naruse@r...>
 
 	* string.c (enc_strlen): move UTF-8 optimization from str_strlen to
Index: string.c
===================================================================
--- string.c	(revision 45617)
+++ string.c	(revision 45618)
@@ -1187,6 +1187,9 @@ rb_enc_strlen(const char *p, const char https://github.com/ruby/ruby/blob/trunk/string.c#L1187
     return enc_strlen(p, e, enc, ENC_CODERANGE_UNKNOWN);
 }
 
+/* To get strlen with cr
+ * Note that given cr is not used.
+ */
 long
 rb_enc_strlen_cr(const char *p, const char *e, rb_encoding *enc, int *cr)
 {
@@ -1243,12 +1246,11 @@ rb_enc_strlen_cr(const char *p, const ch https://github.com/ruby/ruby/blob/trunk/string.c#L1246
     return c;
 }
 
-/* enc must be compatible with str's enc */
+/* enc must be str's enc or rb_enc_check(str, str2) */
 static long
 str_strlen(VALUE str, rb_encoding *enc)
 {
     const char *p, *e;
-    long n;
     int cr;
 
     if (single_byte_optimizable(str)) return RSTRING_LEN(str);
@@ -1257,11 +1259,14 @@ str_strlen(VALUE str, rb_encoding *enc) https://github.com/ruby/ruby/blob/trunk/string.c#L1259
     e = RSTRING_END(str);
     cr = ENC_CODERANGE(str);
 
-    n = rb_enc_strlen_cr(p, e, enc, &cr);
-    if (cr) {
-        ENC_CODERANGE_SET(str, cr);
+    if (cr == ENC_CODERANGE_UNKNOWN) {
+	long n = rb_enc_strlen_cr(p, e, enc, &cr);
+	if (cr) ENC_CODERANGE_SET(str, cr);
+	return n;
+    }
+    else {
+	return enc_strlen(p, e, enc, cr);
     }
-    return n;
 }
 
 long

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

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