ruby-changes:41646
From: naruse <ko1@a...>
Date: Wed, 3 Feb 2016 02:38:05 +0900 (JST)
Subject: [ruby-changes:41646] naruse:r53720 (trunk): * re.c (rb_reg_prepare_enc): use already compiled US-ASCII regexp
naruse 2016-02-03 02:38:00 +0900 (Wed, 03 Feb 2016) New Revision: 53720 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=53720 Log: * re.c (rb_reg_prepare_enc): use already compiled US-ASCII regexp if given string is ASCII only. 121.2s to 113.9s on my x86_64-freebsd10.2 Intel Core i5 661 Modified files: trunk/ChangeLog trunk/re.c Index: re.c =================================================================== --- re.c (revision 53719) +++ re.c (revision 53720) @@ -1374,8 +1374,9 @@ static rb_encoding* https://github.com/ruby/ruby/blob/trunk/re.c#L1374 rb_reg_prepare_enc(VALUE re, VALUE str, int warn) { rb_encoding *enc = 0; + int cr = rb_enc_str_coderange(str); - if (rb_enc_str_coderange(str) == ENC_CODERANGE_BROKEN) { + if (cr == ENC_CODERANGE_BROKEN) { rb_raise(rb_eArgError, "invalid byte sequence in %s", rb_enc_name(rb_enc_get(str))); @@ -1391,14 +1392,19 @@ rb_reg_prepare_enc(VALUE re, VALUE str, https://github.com/ruby/ruby/blob/trunk/re.c#L1392 else if (rb_reg_fixed_encoding_p(re)) { if (RREGEXP_PTR(re)->enc != enc && (!rb_enc_asciicompat(RREGEXP_PTR(re)->enc) || - rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT)) { + cr != ENC_CODERANGE_7BIT)) { reg_enc_error(re, str); } enc = RREGEXP_PTR(re)->enc; } + else if (cr == ENC_CODERANGE_7BIT && + (RREGEXP_PTR(re)->enc == rb_usascii_encoding() + )) { + enc = RREGEXP_PTR(re)->enc; + } if (warn && (RBASIC(re)->flags & REG_ENCODING_NONE) && enc != rb_ascii8bit_encoding() && - rb_enc_str_coderange(str) != ENC_CODERANGE_7BIT) { + cr != ENC_CODERANGE_7BIT) { rb_warn("regexp match /.../n against to %s string", rb_enc_name(enc)); } Index: ChangeLog =================================================================== --- ChangeLog (revision 53719) +++ ChangeLog (revision 53720) @@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Feb 3 02:33:39 2016 NARUSE, Yui <naruse@r...> + + * re.c (rb_reg_prepare_enc): use already compiled US-ASCII regexp + if given string is ASCII only. + 121.2s to 113.9s on my x86_64-freebsd10.2 Intel Core i5 661 + Tue Feb 2 13:02:03 2016 NARUSE, Yui <naruse@r...> * re.c: Introduce RREGEXP_PTR. -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/