8311220: Optimization for StringLatin UpperLower

Reviewed-by: redestad, liach
This commit is contained in:
shaojin.wensj 2023-09-18 17:04:50 +00:00 committed by Claes Redestad
parent 2e2d49c76d
commit f09b7af685

@ -531,10 +531,9 @@ final class StringLatin1 {
}
int first;
final int len = value.length;
// Now check if there are any characters that need to be changed, or are surrogate
// Now check if there are any characters that need to be changed
for (first = 0 ; first < len; first++) {
int cp = value[first] & 0xff;
if (cp != CharacterDataLatin1.instance.toLowerCase(cp)) { // no need to check Character.ERROR
if (CharacterDataLatin1.instance.isUpperCase(value[first] & 0xff)) {
break;
}
}
@ -548,12 +547,7 @@ final class StringLatin1 {
System.arraycopy(value, 0, result, 0, first); // Just copy the first few
// lowerCase characters.
for (int i = first; i < len; i++) {
int cp = value[i] & 0xff;
cp = CharacterDataLatin1.instance.toLowerCase(cp);
if (!canEncode(cp)) { // not a latin1 character
return toLowerCaseEx(str, value, first, locale, false);
}
result[i] = (byte)cp;
result[i] = (byte)CharacterDataLatin1.instance.toLowerCase(value[i] & 0xff);
}
return new String(result, LATIN1);
}
@ -605,10 +599,11 @@ final class StringLatin1 {
int first;
final int len = value.length;
// Now check if there are any characters that need to be changed, or are surrogate
// Now check if there are any characters that need to be changed
for (first = 0 ; first < len; first++ ) {
int cp = value[first] & 0xff;
if (cp != CharacterDataLatin1.instance.toUpperCaseEx(cp)) { // no need to check Character.ERROR
boolean notUpperCaseEx = cp >= 'a' && (cp <= 'z' || cp == 0xb5 || (cp >= 0xdf && cp != 0xf7));
if (notUpperCaseEx) {
break;
}
}
@ -623,8 +618,7 @@ final class StringLatin1 {
System.arraycopy(value, 0, result, 0, first); // Just copy the first few
// upperCase characters.
for (int i = first; i < len; i++) {
int cp = value[i] & 0xff;
cp = CharacterDataLatin1.instance.toUpperCaseEx(cp);
int cp = CharacterDataLatin1.instance.toUpperCaseEx(value[i] & 0xff);
if (!canEncode(cp)) { // not a latin1 character
return toUpperCaseEx(str, value, first, locale, false);
}