ruby-changes:34815
From: nobu <ko1@a...>
Date: Tue, 22 Jul 2014 14:22:37 +0900 (JST)
Subject: [ruby-changes:34815] nobu:r46898 (trunk): string.c: simplify
nobu 2014-07-22 14:22:32 +0900 (Tue, 22 Jul 2014) New Revision: 46898 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=46898 Log: 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. Modified files: trunk/string.c Index: string.c =================================================================== --- string.c (revision 46897) +++ string.c (revision 46898) @@ -6067,19 +6067,19 @@ rb_str_count(int argc, VALUE *argv, VALU https://github.com/ruby/ruby/blob/trunk/string.c#L6067 { 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, VALU https://github.com/ruby/ruby/blob/trunk/string.c#L6095 } 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); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/