Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Backport] JDK-8311220: Optimization for StringLatin UpperLower #718

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -381,10 +381,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 != Character.toLowerCase(cp)) { // no need to check Character.ERROR
if (CharacterDataLatin1.instance.isUpperCase(value[first] & 0xff)) {
break;
}
}
Expand All @@ -398,12 +397,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 = Character.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 @@ -455,10 +449,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 != Character.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 @@ -473,8 +468,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 = Character.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