diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-26 05:10:56 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-09-26 05:10:56 +0000 |
commit | 8d501ec021010dbfdd29d92155bebd82960ad1f1 (patch) | |
tree | 1a7044299593ff78a053b592f94904b1f1cba4d5 /string.c | |
parent | 3973cc582011d2fc38802a311ee537d8d0faa1d7 (diff) |
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
Diffstat (limited to 'string.c')
-rw-r--r-- | string.c | 16 |
1 files changed, 11 insertions, 5 deletions
@@ -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 (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; } |