Skip to content

Commit 2ef616f

Browse files
committed
[optimize] Optimise retrieval of the Document Element for persistent documents
1 parent f2098b8 commit 2ef616f

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

exist-core/src/main/java/org/exist/dom/persistent/DocumentImpl.java

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1300,12 +1300,19 @@ public Text createTextNode(final String data) {
13001300
*/
13011301
@Override
13021302
public Element getDocumentElement() {
1303-
final NodeList cl = getChildNodes();
1304-
for(int i = 0; i < cl.getLength(); i++) {
1305-
if(cl.item(i).getNodeType() == Node.ELEMENT_NODE) {
1306-
return (Element) cl.item(i);
1303+
try (final DBBroker broker = pool.getBroker()) {
1304+
final NodeProxy childNodeProxy = new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE);
1305+
for (int i = 0; i < children; i++) {
1306+
childNodeProxy.setInternalAddress(childAddress[i]);
1307+
final Node child = broker.objectWith(childNodeProxy);
1308+
if (child.getNodeType() == Node.ELEMENT_NODE) {
1309+
return (Element) child;
1310+
}
13071311
}
1312+
} catch(final EXistException e) {
1313+
LOG.warn("Exception while retrieving document element: {}", e.getMessage(), e);
13081314
}
1315+
13091316
return null;
13101317
}
13111318

0 commit comments

Comments
 (0)