From b903c078851353aa410905f7af0d07c65e979ffa Mon Sep 17 00:00:00 2001 From: Alan Paxton Date: Tue, 24 Oct 2023 12:50:13 +0100 Subject: [PATCH] Cache atomized value of NodeProxy MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Can someone who knows better than me confirm whether this is valid ? Looks like about 7.90s —> 7.70s --- .../main/java/org/exist/dom/persistent/NodeProxy.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/exist-core/src/main/java/org/exist/dom/persistent/NodeProxy.java b/exist-core/src/main/java/org/exist/dom/persistent/NodeProxy.java index 347c219af7b..f38e2240ef3 100644 --- a/exist-core/src/main/java/org/exist/dom/persistent/NodeProxy.java +++ b/exist-core/src/main/java/org/exist/dom/persistent/NodeProxy.java @@ -51,6 +51,7 @@ import java.io.IOException; import java.util.Iterator; import java.util.NoSuchElementException; +import java.util.Optional; import java.util.Properties; /** @@ -112,6 +113,11 @@ public class NodeProxy implements NodeSet, NodeValue, NodeHandle, DocumentSet, C private final Expression expression; + /** + * Used to cache the result of {@link #atomize()}. + */ + @Nullable private AtomicValue atomized = null; + /** * Creates a new NodeProxy instance. * @@ -758,7 +764,10 @@ public AtomicValue convertTo(final int requiredType) throws XPathException { @Override public AtomicValue atomize() throws XPathException { - return new UntypedAtomicValue(getNodeValue()); + if (atomized == null) { + atomized = new UntypedAtomicValue(getNodeValue()); + } + return atomized; } @Override