diff --git a/string.c b/string.c index 0425388f375afe..3998006b2faf66 100644 --- a/string.c +++ b/string.c @@ -4443,7 +4443,6 @@ static VALUE str_casecmp_p(VALUE str1, VALUE str2) { rb_encoding *enc; - VALUE folded_str1, folded_str2; VALUE fold_opt = sym_fold; enc = rb_enc_compatible(str1, str2); @@ -4451,8 +4450,19 @@ str_casecmp_p(VALUE str1, VALUE str2) return Qnil; } - folded_str1 = rb_str_downcase(1, &fold_opt, str1); - folded_str2 = rb_str_downcase(1, &fold_opt, str2); + if (ENC_CODERANGE(str1) == ENC_CODERANGE_7BIT && + ENC_CODERANGE(str2) == ENC_CODERANGE_7BIT) { + static const long break_even_point = 120; + long len1 = RSTRING_LEN(str1); + if (len1 != RSTRING_LEN(str2)) return Qfalse; + if (len1 < break_even_point) { + VALUE cmp = str_casecmp(str1, str2); + return RBOOL(cmp == INT2FIX(0)); + } + } + + VALUE folded_str1 = rb_str_downcase(1, &fold_opt, str1); + VALUE folded_str2 = rb_str_downcase(1, &fold_opt, str2); return rb_str_eql(folded_str1, folded_str2); }
Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.
Alternative Proxies: