Skip to content

Commit

Permalink
8266622: Optimize Class.descriptorString() and Class.getCanonicalName0()
Browse files Browse the repository at this point in the history
Reviewed-by: redestad
  • Loading branch information
stsypanov authored and cl4es committed May 14, 2021
1 parent 644f28c commit ebcf399
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/java.base/share/classes/java/lang/Class.java
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}

Expand Down Expand Up @@ -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();
}
}

Expand Down

0 comments on commit ebcf399

Please sign in to comment.