ruby-changes:11597
From: matz <ko1@a...>
Date: Tue, 21 Apr 2009 00:05:59 +0900 (JST)
Subject: [ruby-changes:11597] Ruby:r23234 (trunk): * string.c (rb_str_split_m): faster processing on 7bit strings.
matz 2009-04-21 00:04:18 +0900 (Tue, 21 Apr 2009) New Revision: 23234 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=23234 Log: * string.c (rb_str_split_m): faster processing on 7bit strings. * string.c (ascii_isspace): faster isspace() for 7bit strings. Modified files: trunk/ChangeLog trunk/string.c Index: ChangeLog =================================================================== --- ChangeLog (revision 23233) +++ ChangeLog (revision 23234) @@ -1,3 +1,9 @@ +Mon Apr 20 20:29:04 2009 Yukihiro Matsumoto <matz@r...> + + * string.c (rb_str_split_m): faster processing on 7bit strings. + + * string.c (ascii_isspace): faster isspace() for 7bit strings. + Sun Apr 19 14:43:18 2009 Nobuyoshi Nakada <nobu@r...> * eval.c (ruby_cleanup): the order of local variables on stack is Index: string.c =================================================================== --- string.c (revision 23233) +++ string.c (revision 23234) @@ -5382,7 +5382,27 @@ return INT2NUM(i); } +static const char isspacetable[256] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +}; +#define ascii_isspace(c) isspacetable[(unsigned char)(c)] + /* * call-seq: * str.split(pattern=$;, [limit]) => anArray @@ -5495,21 +5515,45 @@ unsigned int c; end = beg; - while (ptr < eptr) { - c = rb_enc_codepoint(ptr, eptr, enc); - ptr += rb_enc_mbclen(ptr, eptr, enc); - if (skip) { - if (rb_enc_isspace(c, enc)) { + if (is_ascii_string(str)) { + while (ptr < eptr) { + c = (unsigned char)*ptr++; + if (skip) { + if (ascii_isspace(c)) { + beg = ptr - bptr; + } + else { + end = ptr - bptr; + skip = 0; + if (!NIL_P(limit) && lim <= i) break; + } + } + else if (ascii_isspace(c)) { + rb_ary_push(result, rb_str_subseq(str, beg, end-beg)); + skip = 1; beg = ptr - bptr; + if (!NIL_P(limit)) ++i; } else { end = ptr - bptr; - skip = 0; - if (!NIL_P(limit) && lim <= i) break; } } - else { - if (rb_enc_isspace(c, enc)) { + } + else { + while (ptr < eptr) { + c = rb_enc_codepoint(ptr, eptr, enc); + ptr += rb_enc_mbclen(ptr, eptr, enc); + if (skip) { + if (rb_enc_isspace(c, enc)) { + beg = ptr - bptr; + } + else { + end = ptr - bptr; + skip = 0; + if (!NIL_P(limit) && lim <= i) break; + } + } + else if (rb_enc_isspace(c, enc)) { rb_ary_push(result, rb_str_subseq(str, beg, end-beg)); skip = 1; beg = ptr - bptr; -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/