@@ -22,10 +22,6 @@ public class ClassPathNode extends AbstractPathNode<String, ClassInfo> {
2222 * Type identifier for class nodes.
2323 */
2424 public static final String TYPE_ID = "class" ;
25- /**
26- * Name hash for faster {@link #equals(Object)} comparison
27- */
28- private int nameHash = Integer .MIN_VALUE ;
2925
3026 /**
3127 * Node without parent.
@@ -161,17 +157,13 @@ public int localCompare(PathNode<?> o) {
161157 @ Override
162158 public boolean equals (Object o ) {
163159 // If the class names are the same and the parent paths are also equal, then this path points to the same location.
164- if (o instanceof ClassPathNode otherPath )
165- return nameHash () == otherPath .nameHash () && Objects .equals (getParent (), otherPath .getParent ());
160+ if (o instanceof ClassPathNode otherPath ) {
161+ String name = getValue ().getName ();
162+ String otherName = otherPath .getValue ().getName ();
163+ return name .hashCode () == otherName .hashCode () // Hash check first which is very fast, and the result is cached.
164+ && name .equals (otherName ) // Sanity check for matching items to prevent hash collisions.
165+ && Objects .equals (getParent (), otherPath .getParent ()); // Parents must also match.
166+ }
166167 return false ;
167168 }
168-
169- private int nameHash () {
170- // Having many 'equals' calls with string comparisons is slow.
171- // Instead, we compute the hash of the name and do much faster int comparisons.
172- // In practice when using the search UI this moves the bottleneck to the 'instanceof' check.
173- if (nameHash == Integer .MIN_VALUE )
174- nameHash = getValue ().getName ().hashCode ();
175- return nameHash ;
176- }
177169}
0 commit comments