Bypass data tree generation on empty merge 31/13531/1
authorRobert Varga <rovarga@cisco.com>
Wed, 10 Dec 2014 10:30:51 +0000 (11:30 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 10 Dec 2014 10:30:51 +0000 (11:30 +0100)
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 <rovarga@cisco.com>
yang/yang-data-impl/src/main/java/org/opendaylight/yangtools/yang/data/impl/schema/tree/NormalizedNodeContainerModificationStrategy.java

index 52aa03eed2be09bd1d526d5f13e56980b0481a12..cd27513ba036d9261990de4c133bc83a140100c9 100644 (file)
@@ -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<ModifiedNode> 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