Optimize codegen for generic SAM types
Search abstract members in unsubstituted scope to avoid computation of substituted descriptors for each type (effectively for each SAM call) #KT-20055 In progress
This commit is contained in:
@@ -203,7 +203,7 @@ public class ClosureCodegen extends MemberCodegen<KtElement> {
|
||||
erasedInterfaceFunction = getErasedInvokeFunction(funDescriptor);
|
||||
}
|
||||
else {
|
||||
erasedInterfaceFunction = samType.getAbstractMethod().getOriginal();
|
||||
erasedInterfaceFunction = samType.getOriginalAbstractMethod();
|
||||
}
|
||||
|
||||
generateBridge(
|
||||
|
||||
@@ -54,8 +54,8 @@ public class SamType {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public SimpleFunctionDescriptor getAbstractMethod() {
|
||||
return (SimpleFunctionDescriptor) SingleAbstractMethodUtils.getAbstractMembers(type).get(0);
|
||||
public SimpleFunctionDescriptor getOriginalAbstractMethod() {
|
||||
return (SimpleFunctionDescriptor) SingleAbstractMethodUtils.getAbstractMembers(getJavaClassDescriptor()).get(0);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -88,7 +88,7 @@ public class SamWrapperCodegen {
|
||||
/* isExternal = */ false
|
||||
);
|
||||
// e.g. compare(T, T)
|
||||
SimpleFunctionDescriptor erasedInterfaceFunction = samType.getAbstractMethod().getOriginal().copy(
|
||||
SimpleFunctionDescriptor erasedInterfaceFunction = samType.getOriginalAbstractMethod().copy(
|
||||
classDescriptor,
|
||||
Modality.FINAL,
|
||||
Visibilities.PUBLIC,
|
||||
@@ -167,7 +167,7 @@ public class SamWrapperCodegen {
|
||||
|
||||
// generate sam bridges
|
||||
// TODO: erasedInterfaceFunction is actually not an interface function, but function in generated class
|
||||
SimpleFunctionDescriptor originalInterfaceErased = samType.getAbstractMethod().getOriginal();
|
||||
SimpleFunctionDescriptor originalInterfaceErased = samType.getOriginalAbstractMethod();
|
||||
SimpleFunctionDescriptorImpl descriptorForBridges = SimpleFunctionDescriptorImpl
|
||||
.create(erasedInterfaceFunction.getContainingDeclaration(), erasedInterfaceFunction.getAnnotations(), originalInterfaceErased.getName(),
|
||||
CallableMemberDescriptor.Kind.DECLARATION, erasedInterfaceFunction.getSource());
|
||||
|
||||
@@ -899,7 +899,7 @@ public class KotlinTypeMapper {
|
||||
if (expression instanceof KtLambdaExpression) {
|
||||
SamType samType = bindingContext.get(SAM_VALUE, (KtExpression) expression);
|
||||
if (samType != null) {
|
||||
return samType.getAbstractMethod().getName().asString();
|
||||
return samType.getOriginalAbstractMethod().getName().asString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user