* string.c (rb_str_split_m): faster processing on 7bit strings.
* string.c (ascii_isspace): faster isspace() for 7bit strings. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23234 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
c7853b4344
commit
254d12215c
@ -1,3 +1,9 @@
|
|||||||
|
Mon Apr 20 20:29:04 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@ruby-lang.org>
|
Sun Apr 19 14:43:18 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
* eval.c (ruby_cleanup): the order of local variables on stack is
|
* eval.c (ruby_cleanup): the order of local variables on stack is
|
||||||
|
48
string.c
48
string.c
@ -5382,6 +5382,26 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
|||||||
return INT2NUM(i);
|
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:
|
* call-seq:
|
||||||
@ -5495,6 +5515,31 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
unsigned int c;
|
unsigned int c;
|
||||||
|
|
||||||
end = beg;
|
end = beg;
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
while (ptr < eptr) {
|
while (ptr < eptr) {
|
||||||
c = rb_enc_codepoint(ptr, eptr, enc);
|
c = rb_enc_codepoint(ptr, eptr, enc);
|
||||||
ptr += rb_enc_mbclen(ptr, eptr, enc);
|
ptr += rb_enc_mbclen(ptr, eptr, enc);
|
||||||
@ -5508,8 +5553,7 @@ rb_str_split_m(int argc, VALUE *argv, VALUE str)
|
|||||||
if (!NIL_P(limit) && lim <= i) break;
|
if (!NIL_P(limit) && lim <= i) break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else if (rb_enc_isspace(c, enc)) {
|
||||||
if (rb_enc_isspace(c, enc)) {
|
|
||||||
rb_ary_push(result, rb_str_subseq(str, beg, end-beg));
|
rb_ary_push(result, rb_str_subseq(str, beg, end-beg));
|
||||||
skip = 1;
|
skip = 1;
|
||||||
beg = ptr - bptr;
|
beg = ptr - bptr;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user