@@ -283,6 +283,12 @@ final boolean singleByteOptimizable(Encoding enc) {
283283 return StringSupport .isSingleByteOptimizable (this , enc );
284284 }
285285
286+ // case_option_single_p
287+ final boolean singleCaseFold (int flags , Encoding encoding ) {
288+ return (((flags & Config .CASE_ASCII_ONLY ) != 0 && (encoding .isUTF8 () || encoding .maxLength () == 1 )) ||
289+ !((flags & Config .CASE_FOLD_TURKISH_AZERI ) != 0 && getCodeRange () == CR_7BIT ));
290+ }
291+
286292 @ SuppressWarnings ("ReferenceEquality" )
287293 final Encoding isCompatibleWith (EncodingCapable other ) {
288294 if (other instanceof RubyString ) return checkEncoding ((RubyString )other );
@@ -1926,8 +1932,7 @@ public IRubyObject upcase_bang(ThreadContext context, IRubyObject arg0, IRubyObj
19261932 private IRubyObject upcase_bang (ThreadContext context , int flags ) {
19271933 modifyAndKeepCodeRange ();
19281934 Encoding enc = checkDummyEncoding ();
1929- if (((flags & Config .CASE_ASCII_ONLY ) != 0 && (enc .isUTF8 () || enc .maxLength () == 1 )) ||
1930- (flags & Config .CASE_FOLD_TURKISH_AZERI ) == 0 && getCodeRange () == CR_7BIT ) {
1935+ if (singleCaseFold (flags , enc )) {
19311936 int s = value .getBegin ();
19321937 int end = s + value .getRealSize ();
19331938 byte []bytes = value .getUnsafeBytes ();
@@ -2000,8 +2005,7 @@ public IRubyObject downcase_bang(ThreadContext context, IRubyObject arg0, IRubyO
20002005 private IRubyObject downcase_bang (ThreadContext context , int flags ) {
20012006 modifyAndKeepCodeRange ();
20022007 Encoding enc = checkDummyEncoding ();
2003- if (((flags & Config .CASE_ASCII_ONLY ) != 0 && (enc .isUTF8 () || enc .maxLength () == 1 )) ||
2004- (flags & Config .CASE_FOLD_TURKISH_AZERI ) == 0 && getCodeRange () == CR_7BIT ) {
2008+ if (singleCaseFold (flags , enc )) {
20052009 int s = value .getBegin ();
20062010 int end = s + value .getRealSize ();
20072011 byte []bytes = value .getUnsafeBytes ();
0 commit comments