Optimize AbstractClassTypeConstructor::equals

This commit is contained in:
Denis Zharkov
2017-07-21 15:27:40 +03:00
parent 8753baeab6
commit fbdcf45976
@@ -19,7 +19,6 @@ package org.jetbrains.kotlin.types;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.kotlin.builtins.KotlinBuiltIns;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.name.FqNameUnsafe;
import org.jetbrains.kotlin.resolve.DescriptorUtils;
import org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilsKt;
import org.jetbrains.kotlin.storage.StorageManager;
@@ -62,6 +61,7 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
@Override
public final boolean equals(Object other) {
if (this == other) return true;
if (!(other instanceof TypeConstructor)) return false;
// performance optimization: getFqName is slow method
@@ -74,13 +74,11 @@ public abstract class AbstractClassTypeConstructor extends AbstractTypeConstruct
ClassifierDescriptor myDescriptor = getDeclarationDescriptor();
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).getDeclarationDescriptor();
// descriptor for type is created once per module
if (myDescriptor == otherDescriptor) return true;
// All error types have the same descriptor
if (!hasMeaningfulFqName(myDescriptor) ||
otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
return this == other;
// All error types and local classes have the same descriptor,
// but we've already checked identity equality in the beginning of the method
return false;
}
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {