* string.c (rb_str_count): optimized for 1byte string count by
avoiding tr_setup_table(). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@23523 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
1b4d0c76de
commit
3ee7fcc763
@ -53,6 +53,11 @@ Wed May 20 18:34:30 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
|||||||
|
|
||||||
* enumerator.c (inspect_enumerator): should use long.
|
* enumerator.c (inspect_enumerator): should use long.
|
||||||
|
|
||||||
|
Wed May 20 09:18:44 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
|
* string.c (rb_str_count): optimized for 1byte string count by
|
||||||
|
avoiding tr_setup_table().
|
||||||
|
|
||||||
Wed May 20 06:25:29 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
Wed May 20 06:25:29 2009 Yukihiro Matsumoto <matz@ruby-lang.org>
|
||||||
|
|
||||||
* encoding.c (rb_enc_fast_mbclen): faster mbclen for strings known
|
* encoding.c (rb_enc_fast_mbclen): faster mbclen for strings known
|
||||||
|
24
string.c
24
string.c
@ -5380,19 +5380,31 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
|||||||
rb_raise(rb_eArgError, "wrong number of arguments");
|
rb_raise(rb_eArgError, "wrong number of arguments");
|
||||||
}
|
}
|
||||||
for (i=0; i<argc; i++) {
|
for (i=0; i<argc; i++) {
|
||||||
VALUE s = argv[i];
|
VALUE tstr = argv[i];
|
||||||
|
unsigned char c;
|
||||||
|
|
||||||
StringValue(s);
|
StringValue(tstr);
|
||||||
enc = rb_enc_check(str, s);
|
enc = rb_enc_check(str, tstr);
|
||||||
tr_setup_table(s, table, i==0, &del, &nodel, enc);
|
if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
|
||||||
|
(c = RSTRING_PTR(tstr)[0]) < 0x80 && !is_broken_string(str)) {
|
||||||
|
int n = 0;
|
||||||
|
|
||||||
|
s = RSTRING_PTR(str);
|
||||||
|
if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
|
||||||
|
send = RSTRING_END(str);
|
||||||
|
while (s < send) {
|
||||||
|
if (*(unsigned char*)s++ == c) n++;
|
||||||
|
}
|
||||||
|
return INT2NUM(n);
|
||||||
|
}
|
||||||
|
tr_setup_table(tstr, table, i==0, &del, &nodel, enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = RSTRING_PTR(str);
|
s = RSTRING_PTR(str);
|
||||||
if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
|
if (!s || RSTRING_LEN(str) == 0) return INT2FIX(0);
|
||||||
send = RSTRING_END(str);
|
send = RSTRING_END(str);
|
||||||
i = 0;
|
|
||||||
ascompat = rb_enc_asciicompat(enc);
|
ascompat = rb_enc_asciicompat(enc);
|
||||||
|
i = 0;
|
||||||
while (s < send) {
|
while (s < send) {
|
||||||
unsigned int c;
|
unsigned int c;
|
||||||
int clen;
|
int clen;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user