diff options
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | string.c | 16 |
2 files changed, 17 insertions, 5 deletions
@@ -1,3 +1,9 @@ +Mon Sep 26 14:10:54 2016 Ary Borenszweig <ary@esperanto.org.ar> + + * 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@ruby-lang.org> * gems/bundled_gems: update to minitest-5.9.1. @@ -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; } |