Skip to content

Commit

Permalink
8311220: Optimization for StringLatin UpperLower
Browse files Browse the repository at this point in the history
Reviewed-by: redestad, liach
  • Loading branch information
wenshao authored and cl4es committed Sep 18, 2023
1 parent 2e2d49c commit f09b7af
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/java.base/share/classes/java/lang/StringLatin1.java
Original file line number Diff line number Diff line change
Expand Up @@ -531,10 +531,9 @@ public static String toLowerCase(String str, byte[] value, Locale locale) {
}
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;
}
}
Expand All @@ -548,12 +547,7 @@ public static String toLowerCase(String str, byte[] value, Locale locale) {
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);
}
Expand Down Expand Up @@ -605,10 +599,11 @@ public static String toUpperCase(String str, byte[] value, Locale locale) {
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;
}
}
Expand All @@ -623,8 +618,7 @@ public static String toUpperCase(String str, byte[] value, Locale locale) {
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);
}
Expand Down

1 comment on commit f09b7af

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.