Skip to content
Permalink
Browse files
8266622: Optimize Class.descriptorString() and Class.getCanonicalName0()
Reviewed-by: redestad
  • Loading branch information
stsypanov authored and cl4es committed May 14, 2021
1 parent 644f28c commit ebcf3991b79024ef35512e5aa2be5bd731acf9e0
Showing with 19 additions and 4 deletions.
  1. +19 −4 src/java.base/share/classes/java/lang/Class.java
@@ -1722,7 +1722,12 @@ private String getCanonicalName0() {
String enclosingName = enclosingClass.getCanonicalName();
if (enclosingName == null)
return ReflectionData.NULL_SENTINEL;
return enclosingName + "." + getSimpleName();
String simpleName = getSimpleName();
return new StringBuilder(enclosingName.length() + simpleName.length() + 1)
.append(enclosingName)
.append('.')
.append(simpleName)
.toString();
}
}

@@ -4365,10 +4370,20 @@ public String descriptorString() {
} else if (isHidden()) {
String name = getName();
int index = name.indexOf('/');
return "L" + name.substring(0, index).replace('.', '/')
+ "." + name.substring(index+1) + ";";
return new StringBuilder(name.length() + 2)
.append('L')
.append(name.substring(0, index).replace('.', '/'))
.append('.')
.append(name, index + 1, name.length())
.append(';')
.toString();
} else {
return "L" + getName().replace('.', '/') + ";";
String name = getName().replace('.', '/');
return new StringBuilder(name.length() + 2)
.append('L')
.append(name)
.append(';')
.toString();
}
}

0 comments on commit ebcf399

Please sign in to comment.