From b34a78863a24383c204b1e57524e5f0d4b9f21e3 Mon Sep 17 00:00:00 2001 From: Alan Paxton Date: Mon, 27 Nov 2023 17:00:59 +0000 Subject: [PATCH] [optimise] Faster NamePool comparison MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Especially if entries have been intern()-ed, which they ‘ave (in Inigo Montoya accent) --- .../org/exist/util/hashtable/NamePool.java | 31 ++++++++++++++----- 1 file changed, 23 insertions(+), 8 deletions(-) diff --git a/exist-core/src/main/java/org/exist/util/hashtable/NamePool.java b/exist-core/src/main/java/org/exist/util/hashtable/NamePool.java index 2078436c81e..62125bc2c0a 100644 --- a/exist-core/src/main/java/org/exist/util/hashtable/NamePool.java +++ b/exist-core/src/main/java/org/exist/util/hashtable/NamePool.java @@ -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