Skip to content

Commit 579ba27

Browse files
committed
[bugfix] Reduce NodeProxy object creation in persistent document operations
1 parent 8b12754 commit 579ba27

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
@@ -1029,14 +1029,13 @@ public IStoredNode updateChild(final Txn transaction, final Node oldChild, final
10291029
@Override
10301030
@EnsureContainerLocked(mode=READ_LOCK)
10311031
public Node getFirstChild() {
1032-
if(children == 0) {
1032+
if (children == 0) {
10331033
return null;
10341034
}
1035-
try(final DBBroker broker = pool.getBroker()) {
1036-
return broker.objectWith(new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE, childAddress[0]));
1037-
} catch(final EXistException e) {
1035+
try (final DBBroker broker = pool.getBroker()) {
1036+
return broker.objectWith(getFirstChildProxy());
1037+
} catch (final EXistException e) {
10381038
LOG.warn("Exception while inserting node: {}", e.getMessage(), e);
1039-
//TODO : throw exception ?
10401039
}
10411040
return null;
10421041
}
@@ -1069,14 +1068,18 @@ public boolean hasChildNodes() {
10691068
@EnsureContainerLocked(mode=READ_LOCK)
10701069
public NodeList getChildNodes() {
10711070
final org.exist.dom.NodeListImpl list = new org.exist.dom.NodeListImpl();
1071+
1072+
@Nullable final NodeProxy nodeProxy = children > 0 ? new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE) : null;
10721073
try (final DBBroker broker = pool.getBroker()) {
1073-
for(int i = 0; i < children; i++) {
1074-
final Node child = broker.objectWith(new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE, childAddress[i]));
1074+
for (int i = 0; i < children; i++) {
1075+
nodeProxy.setInternalAddress(childAddress[i]);
1076+
final Node child = broker.objectWith(nodeProxy);
10751077
list.add(child);
10761078
}
1077-
} catch(final EXistException e) {
1079+
} catch (final EXistException e) {
10781080
LOG.warn("Exception while retrieving child nodes: {}", e.getMessage(), e);
10791081
}
1082+
10801083
return list;
10811084
}
10821085

@@ -1397,7 +1400,7 @@ public Text createTextNode(final String data) {
13971400
@Override
13981401
public Element getDocumentElement() {
13991402
try (final DBBroker broker = pool.getBroker()) {
1400-
final NodeProxy childNodeProxy = new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE);
1403+
@Nullable final NodeProxy childNodeProxy = children > 0 ? new NodeProxy(getExpression(), this, NodeId.DOCUMENT_NODE) : null;
14011404
for (int i = 0; i < children; i++) {
14021405
childNodeProxy.setInternalAddress(childAddress[i]);
14031406
final Node child = broker.objectWith(childNodeProxy);

0 commit comments

Comments
 (0)