Skip to content

Commit 32b2d25

Browse files
committed
[bugfix] Reduce NodeProxy object creation in persistent document operations
1 parent 6afae23 commit 32b2d25

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

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

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -955,14 +955,13 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
955955
@Override
956956
@EnsureContainerLocked(mode=READ_LOCK)
957957
public Node getFirstChild() {
958-
if(children == 0) {
958+
if (children == 0) {
959959
return null;
960960
}
961-
try(final DBBroker broker = pool.getBroker()) {
962-
return broker.objectWith(new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE, childAddress[0]));
963-
} catch(final EXistException e) {
961+
try (final DBBroker broker = pool.getBroker()) {
962+
return broker.objectWith(getFirstChildProxy());
963+
} catch (final EXistException e) {
964964
LOG.warn("Exception while inserting node: {}", e.getMessage(), e);
965-
//TODO : throw exception ?
966965
}
967966
return null;
968967
}
@@ -995,14 +994,18 @@ public boolean hasChildNodes() {
995994
@EnsureContainerLocked(mode=READ_LOCK)
996995
public NodeList getChildNodes() {
997996
final org.exist.dom.NodeListImpl list = new org.exist.dom.NodeListImpl();
997+
998+
@Nullable final NodeProxy nodeProxy = children > 0 ? new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE) : null;
998999
try (final DBBroker broker = pool.getBroker()) {
999-
for(int i = 0; i < children; i++) {
1000-
final Node child = broker.objectWith(new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE, childAddress[i]));
1000+
for (int i = 0; i < children; i++) {
1001+
nodeProxy.setInternalAddress(childAddress[i]);
1002+
final Node child = broker.objectWith(nodeProxy);
10011003
list.add(child);
10021004
}
1003-
} catch(final EXistException e) {
1005+
} catch (final EXistException e) {
10041006
LOG.warn("Exception while retrieving child nodes: {}", e.getMessage(), e);
10051007
}
1008+
10061009
return list;
10071010
}
10081011

@@ -1308,7 +1311,7 @@ public Text createTextNode(final String data) {
13081311
@Override
13091312
public Element getDocumentElement() {
13101313
try (final DBBroker broker = pool.getBroker()) {
1311-
final NodeProxy childNodeProxy = new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE);
1314+
@Nullable final NodeProxy childNodeProxy = children > 0 ? new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE) : null;
13121315
for (int i = 0; i < children; i++) {
13131316
childNodeProxy.setInternalAddress(childAddress[i]);
13141317
final Node child = broker.objectWith(childNodeProxy);

0 commit comments

Comments
 (0)