This commit is contained in:
Erik Berlin 2025-08-14 19:38:40 +03:00 committed by GitHub
commit 9d2524fed8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -4422,7 +4422,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);
@ -4430,8 +4429,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);
}