Optimized equals method for TypeConstructor
This commit is contained in:
@@ -44,17 +44,21 @@ public abstract class AbstractClassTypeConstructor implements TypeConstructor {
|
|||||||
public static boolean equals(@NotNull TypeConstructor me, Object other) {
|
public static boolean equals(@NotNull TypeConstructor me, Object other) {
|
||||||
if (!(other instanceof TypeConstructor)) return false;
|
if (!(other instanceof TypeConstructor)) return false;
|
||||||
|
|
||||||
|
// performance optimization: getFqName is slow method
|
||||||
|
if (other.hashCode() != me.hashCode()) return false;
|
||||||
|
|
||||||
ClassifierDescriptor myDescriptor = me.getDeclarationDescriptor();
|
ClassifierDescriptor myDescriptor = me.getDeclarationDescriptor();
|
||||||
ClassifierDescriptor otherDescriptor = ((TypeConstructor) other).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
|
// All error types have the same descriptor
|
||||||
if (myDescriptor != null && !hasMeaningfulFqName(myDescriptor) ||
|
if (myDescriptor != null && !hasMeaningfulFqName(myDescriptor) ||
|
||||||
otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
|
otherDescriptor != null && !hasMeaningfulFqName(otherDescriptor)) {
|
||||||
return me == other;
|
return me == other;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (myDescriptor == otherDescriptor) return true;
|
|
||||||
|
|
||||||
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
|
if (myDescriptor instanceof ClassDescriptor && otherDescriptor instanceof ClassDescriptor) {
|
||||||
FqNameUnsafe otherFqName = DescriptorUtils.getFqName(otherDescriptor);
|
FqNameUnsafe otherFqName = DescriptorUtils.getFqName(otherDescriptor);
|
||||||
FqNameUnsafe myFqName = DescriptorUtils.getFqName(myDescriptor);
|
FqNameUnsafe myFqName = DescriptorUtils.getFqName(myDescriptor);
|
||||||
|
|||||||
Reference in New Issue
Block a user