From 8d501ec021010dbfdd29d92155bebd82960ad1f1 Mon Sep 17 00:00:00 2001 From: nobu Date: Mon, 26 Sep 2016 05:10:56 +0000 Subject: [PATCH] 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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56250 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ChangeLog | 6 ++++++ string.c | 18 ++++++++++++------ 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/ChangeLog b/ChangeLog index 78be5fc367..e3ba79e450 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +Mon Sep 26 14:10:54 2016 Ary Borenszweig + + * 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 * gems/bundled_gems: update to minitest-5.9.1. diff --git a/string.c b/string.c index c537bbf4ab..8a57bc9048 100644 --- a/string.c +++ b/string.c @@ -8041,13 +8041,19 @@ lstrip_offset(VALUE str, const char *s, const char *e, rb_encoding *enc) 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 (!rb_isspace(cc)) break; - s += n; + /* remove spaces at head */ + 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; + } } return s - start; }