From: Robert Varga Date: Wed, 10 Dec 2014 10:30:51 +0000 (+0100) Subject: Bypass data tree generation on empty merge X-Git-Tag: release/lithium~408^2 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=93b0b3872f0a7a4f41c2db5d4c97669d66c8d5d2;p=yangtools.git Bypass data tree generation on empty merge A merge operation may end up not introducing any child nodes. Current code forces a mutable/immutable cycle. This may end up copying maps or creating a TrieMap snapshot -- which is not then modified and directly reused. This introduces a simple check and a shortcut, which just creates a new metadata node. Change-Id: I3fe4d07a139986d473a6bf55a2b40ff4350bd699 Signed-off-by: Robert Varga --- diff --git a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java index 52aa03eed2..cd27513ba0 100644 --- a/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java +++ b/yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java @@ -148,10 +148,20 @@ abstract class NormalizedNodeContainerModificationStrategy extends SchemaAwareAp final MutableTreeNode newMeta = currentMeta.mutable(); newMeta.setSubtreeVersion(version); + /* + * The user has issued an empty merge operation. In this case we do not perform + * a data tree mutation, do not pass GO, and do not collect useless garbage. + */ + final Iterable children = modification.getChildren(); + if (Iterables.isEmpty(children)) { + newMeta.setData(currentMeta.getData()); + return newMeta.seal(); + } + @SuppressWarnings("rawtypes") NormalizedNodeContainerBuilder dataBuilder = createBuilder(currentMeta.getData()); - return mutateChildren(newMeta, dataBuilder, version, modification.getChildren()); + return mutateChildren(newMeta, dataBuilder, version, children); } @Override