summaryrefslogtreecommitdiff
path: root/string.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-22 05:22:32 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-22 05:22:32 +0000
commit98b2401077925daee44f4b7311f114c01c5f25ea (patch)
treed78ddc9da6353ac36c3631807117f2711c6c32ea /string.c
parentd2d9257cd4b122fc5a7dca40594365d765e52011 (diff)
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
Diffstat (limited to 'string.c')
-rw-r--r--string.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/string.c b/string.c
index f0ce9b1109..9f06837789 100644
--- a/string.c
+++ b/string.c
@@ -6067,19 +6067,19 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
{
char table[TR_TABLE_SIZE];
rb_encoding *enc = 0;
- VALUE del = 0, nodel = 0;
+ VALUE del = 0, nodel = 0, tstr;
char *s, *send;
int i;
int ascompat;
rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS);
- for (i=0; i<argc; i++) {
- VALUE tstr = argv[i];
- const char *ptstr;
- StringValue(tstr);
- enc = rb_enc_check(str, tstr);
- if (argc == 1 && RSTRING_LEN(tstr) == 1 && rb_enc_asciicompat(enc) &&
+ tstr = argv[0];
+ StringValue(tstr);
+ 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),
ONIGENC_IS_ALLOWED_REVERSE_MATCH(enc, (const unsigned char *)ptstr, (const unsigned char *)ptstr+1)) &&
!is_broken_string(str)) {
@@ -6095,7 +6095,14 @@ rb_str_count(int argc, VALUE *argv, VALUE str)
}
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);