Skip to content

Commit

Permalink
[optimise] Faster NamePool comparison
Browse files Browse the repository at this point in the history
Especially if entries have been intern()-ed, which they ‘ave (in Inigo Montoya accent)
  • Loading branch information
alanpaxton authored and adamretter committed Dec 1, 2024
1 parent 55af961 commit b34a788
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions exist-core/src/main/java/org/exist/util/hashtable/NamePool.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,30 @@ public int compareTo(final WrappedQName other) {
if (qname.getNameType() != other.qname.getNameType()) {
return qname.getNameType() < other.qname.getNameType() ? Constants.INFERIOR : Constants.SUPERIOR;
}
final int c;
if (qname.getNamespaceURI() == null) {
c = other.qname.getNamespaceURI() == null ? Constants.EQUAL : Constants.INFERIOR;
} else if (other.qname.getNamespaceURI() == null) {
c = Constants.SUPERIOR;
} else {
c = qname.getNamespaceURI().compareTo(other.qname.getNamespaceURI());
int c = Constants.EQUAL;
final String nsURI = qname.getNamespaceURI();
final String nsURIOther = other.qname.getNamespaceURI();
if (nsURI != nsURIOther) {
if (nsURI == null) {
return Constants.INFERIOR;
} else if (nsURIOther == null) {
return Constants.SUPERIOR;
} else {
c = nsURI.compareTo(nsURIOther);
}
}
if (c != Constants.EQUAL) {
return c;
}
return c == Constants.EQUAL ? qname.getLocalPart().compareTo(other.qname.getLocalPart()) : c;

final String local = qname.getLocalPart();
final String localOther = other.qname.getLocalPart();
if (local != localOther) {
return local.compareTo(localOther);
}
return Constants.EQUAL;

//TODO (AP) Why is prefix not in this comparison ? (it never was)
}

@Override
Expand Down

0 comments on commit b34a788

Please sign in to comment.