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

ruby-changes:44177

From: nobu <ko1@a...>
Date: Mon, 26 Sep 2016 14:11:01 +0900 (JST)
Subject: [ruby-changes:44177] nobu:r56250 (trunk): string.c: fast path of lstrip_offset

nobu	2016-09-26 14:10:56 +0900 (Mon, 26 Sep 2016)

  New Revision: 56250

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

  Log:
    string.c: fast path of lstrip_offset
    
    * string.c (lstrip_offset): add a fast path in the case of single
      byte optimizable strings, as well as rstrip_offset.
      [ruby-core:77392] [Feature #12788]

  Modified files:
    trunk/ChangeLog
    trunk/string.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 56249)
+++ ChangeLog	(revision 56250)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Sep 26 14:10:54 2016  Ary Borenszweig  <ary@e...>
+
+	* string.c (lstrip_offset): add a fast path in the case of single
+	  byte optimizable strings, as well as rstrip_offset.
+	  [ruby-core:77392] [Feature #12788]
+
 Mon Sep 26 12:00:12 2016  Nobuyoshi Nakada  <nobu@r...>
 
 	* gems/bundled_gems: update to minitest-5.9.1.
Index: string.c
===================================================================
--- string.c	(revision 56249)
+++ string.c	(revision 56250)
@@ -8041,13 +8041,19 @@ lstrip_offset(VALUE str, const char *s, https://github.com/ruby/ruby/blob/trunk/string.c#L8041
     const char *const start = s;
 
     if (!s || s >= e) return 0;
+
     /* remove spaces at head */
-    while (s < e) {
-	int n;
-	unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
+    if (single_byte_optimizable(str)) {
+	while (s < e && ascii_isspace(*s)) s++;
+    }
+    else {
+	while (s < e) {
+	    int n;
+	    unsigned int cc = rb_enc_codepoint_len(s, e, &n, enc);
 
-	if (!rb_isspace(cc)) break;
-	s += n;
+	    if (!rb_isspace(cc)) break;
+	    s += n;
+	}
     }
     return s - start;
 }

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

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