Optimize getSingleAbstractMethodOrNull

Searching for the single abstract method leads to computing
whole member scopes of given intrefaces, especially when
they contain a lot of methods (i.e. they're definitely not SAMs)

On the other side this method is very hot because it's called
for each Java interface used as a type for some value parameter
(for building SAM adapters)

The idea is to apply some heuristics to understand using only
JavaMethod and supertypes that this interface is definitely not a SAM
This commit is contained in:
Denis Zharkov
2017-03-24 12:44:04 +03:00
parent db3f70cfe9
commit e4cb5496b8
4 changed files with 35 additions and 5 deletions
@@ -128,10 +128,8 @@ public class SingleAbstractMethodUtils {
}
@Nullable
public static FunctionDescriptor getSingleAbstractMethodOrNull(@NotNull ClassDescriptor klass) {
if (klass.getKind() != ClassKind.INTERFACE) {
return null;
}
public static FunctionDescriptor getSingleAbstractMethodOrNull(@NotNull JavaClassDescriptor klass) {
if (klass.isDefinitelyNotSamInterface()) return null;
if (DescriptorUtilsKt.getFqNameSafe(klass).asString().equals("android.databinding.DataBindingComponent")) {
return null;