string.c: simplify
* string.c (rb_str_count): move code for the first argument outside loop for the rest, as it is executed only once. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@46898 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
d2d9257cd4
commit
98b2401077
23
string.c
23
string.c
@ -6067,19 +6067,19 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
|||||||
{
|
{
|
||||||
char table[TR_TABLE_SIZE];
|
char table[TR_TABLE_SIZE];
|
||||||
rb_encoding *enc = 0;
|
rb_encoding *enc = 0;
|
||||||
VALUE del = 0, nodel = 0;
|
VALUE del = 0, nodel = 0, tstr;
|
||||||
char *s, *send;
|
char *s, *send;
|
||||||
int i;
|
int i;
|
||||||
int ascompat;
|
int ascompat;
|
||||||
|
|
||||||
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
|
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
|
||||||
for (i=0; i<argc; i++) {
|
|
||||||
VALUE tstr = argv[i];
|
|
||||||
const char *ptstr;
|
|
||||||
|
|
||||||
StringValue(tstr);
|
tstr = argv[0];
|
||||||
enc = rb_enc_check(str, tstr);
|
StringValue(tstr);
|
||||||
if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
|
enc = rb_enc_check(str, tstr);
|
||||||
|
if (argc == 1) {
|
||||||
|
const char *ptstr;
|
||||||
|
if (RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
|
||||||
(ptstr = RSTRING_PTR(tstr),
|
(ptstr = RSTRING_PTR(tstr),
|
||||||
ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
|
ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
|
||||||
!is_broken_string(str)) {
|
!is_broken_string(str)) {
|
||||||
@ -6095,7 +6095,14 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
|
|||||||
}
|
}
|
||||||
return INT2NUM(n);
|
return INT2NUM(n);
|
||||||
}
|
}
|
||||||
tr_setup_table(tstr, table, i==0, &del, &nodel, enc);
|
}
|
||||||
|
|
||||||
|
tr_setup_table(tstr, table, TRUE, &del, &nodel, enc);
|
||||||
|
for (i=1; i<argc; i++) {
|
||||||
|
tstr = argv[i];
|
||||||
|
StringValue(tstr);
|
||||||
|
enc = rb_enc_check(str, tstr);
|
||||||
|
tr_setup_table(tstr, table, FALSE, &del, &nodel, enc);
|
||||||
}
|
}
|
||||||
|
|
||||||
s = RSTRING_PTR(str);
|
s = RSTRING_PTR(str);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user