Index: string.c =================================================================== --- string.c (revision 56246) +++ string.c (working copy) @@ -8039,13 +8039,19 @@ 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; }