mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8331114: Further improve performance of MethodTypeDesc::descriptorString
Reviewed-by: mchung, liach
This commit is contained in:
parent
e3eb652c25
commit
a078b5e611
5 changed files with 33 additions and 15 deletions
|
@ -160,7 +160,7 @@ public sealed interface ClassDesc
|
|||
static ClassDesc ofDescriptor(String descriptor) {
|
||||
// implicit null-check
|
||||
return (descriptor.length() == 1)
|
||||
? Wrapper.forPrimitiveType(descriptor.charAt(0)).primitiveClassDescriptor()
|
||||
? Wrapper.forPrimitiveType(descriptor.charAt(0)).classDescriptor()
|
||||
// will throw IAE on descriptor.length == 0 or if array dimensions too long
|
||||
: new ReferenceClassDescImpl(descriptor);
|
||||
}
|
||||
|
|
|
@ -226,7 +226,7 @@ class ConstantUtils {
|
|||
|
||||
private static ClassDesc resolveClassDesc(String descriptor, int start, int len) {
|
||||
if (len == 1) {
|
||||
return Wrapper.forBasicType(descriptor.charAt(start)).primitiveClassDescriptor();
|
||||
return Wrapper.forPrimitiveType(descriptor.charAt(start)).classDescriptor();
|
||||
}
|
||||
return ClassDesc.ofDescriptor(descriptor.substring(start, start + len));
|
||||
}
|
||||
|
|
|
@ -33,7 +33,6 @@ import java.security.PrivilegedAction;
|
|||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
import java.util.StringJoiner;
|
||||
|
||||
import static java.util.Objects.requireNonNull;
|
||||
|
||||
|
@ -168,11 +167,17 @@ final class MethodTypeDescImpl implements MethodTypeDesc {
|
|||
if (desc != null)
|
||||
return desc;
|
||||
|
||||
var sj = new StringJoiner("", "(", ")" + returnType().descriptorString());
|
||||
for (int i = 0; i < parameterCount(); i++) {
|
||||
sj.add(parameterType(i).descriptorString());
|
||||
int len = 2 + returnType.descriptorString().length();
|
||||
for (ClassDesc argType : argTypes) {
|
||||
len += argType.descriptorString().length();
|
||||
}
|
||||
return cachedDescriptorString = sj.toString();
|
||||
StringBuilder sb = new StringBuilder(len).append('(');
|
||||
for (ClassDesc argType : argTypes) {
|
||||
sb.append(argType.descriptorString());
|
||||
}
|
||||
desc = sb.append(')').append(returnType.descriptorString()).toString();
|
||||
cachedDescriptorString = desc;
|
||||
return desc;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue