From 73e7703db2dd0b5b55038a3345faa70ab82dfa89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yann=20C=C3=A9bron?= Date: Wed, 12 Nov 2014 09:26:45 +0100 Subject: [PATCH] StubParentStrategy: equals() performance use DomStub information instead of accessing XML --- .../com/intellij/util/xml/stubs/DomStub.java | 20 +++++++++++++++++++ .../util/xml/stubs/StubParentStrategy.java | 17 ++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java index 45a4b8637679..0a0823d532c9 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/DomStub.java @@ -134,4 +134,24 @@ public abstract class DomStub extends ObjectStubBase { } public abstract int getIndex(); + + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + + DomStub stub = (DomStub)o; + if (stub.getIndex() != getIndex()) return false; + if (stub.isCustom() != isCustom()) return false; + + return Comparing.strEqual(stub.getName(), getName()) && + Comparing.strEqual(stub.getNamespaceKey(), getNamespaceKey()); + } + + @Override + public int hashCode() { + int result = myLocalName.hashCode(); + result = 31 * result + myNamespace.hashCode(); + return result; + } } diff --git a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java index 951c6f576249..25d093ad3d32 100644 --- a/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java +++ b/xml/dom-impl/src/com/intellij/util/xml/stubs/StubParentStrategy.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2012 JetBrains s.r.o. + * Copyright 2000-2014 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -16,6 +16,7 @@ package com.intellij.util.xml.stubs; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Comparing; import com.intellij.psi.xml.XmlElement; import com.intellij.psi.xml.XmlFile; import com.intellij.psi.xml.XmlTag; @@ -139,7 +140,19 @@ public class StubParentStrategy implements DomParentStrategy { @SuppressWarnings("EqualsWhichDoesntCheckParameterClass") @Override public boolean equals(Object obj) { - return PhysicalDomParentStrategy.strategyEquals(this, obj); + if (!(obj instanceof StubParentStrategy)) { + return PhysicalDomParentStrategy.strategyEquals(this, obj); + } + + if (obj == this) return true; + + StubParentStrategy other = (StubParentStrategy)obj; + if (!other.getClass().equals(getClass())) return false; + + if (!other.myStub.equals(myStub)) return false; + + return Comparing.equal(getContainingFile(myStub.getHandler()), + other.getContainingFile(other.myStub.getHandler())); } public static class Empty extends StubParentStrategy {