Use EmptyLeafEffectiveStatement in copyLeaf() 53/98853/2
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Dec 2021 08:52:05 +0000 (09:52 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Dec 2021 10:42:51 +0000 (11:42 +0100)
If the arguments match, we can reuse empty leaf, as there is no other
state we keep.

JIRA: YANGTOOLS-1316
Change-Id: Ia822beba18834d291c33db0007c3686427d1069c
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/stmt/EffectiveStatements.java
model/yang-model-ri/src/main/java/org/opendaylight/yangtools/yang/model/ri/stmt/impl/eff/EmptyLeafEffectiveStatement.java

index 1f70204a9cbec749c0e6fed405069698e509ac0e..93b310707bda294aef1e521382cc462c768481f4 100644 (file)
@@ -565,7 +565,9 @@ public final class EffectiveStatements {
     public static LeafEffectiveStatement copyLeaf(final LeafEffectiveStatement original, final QName argument,
             final int flags) {
         checkArgument(original instanceof AbstractLeafEffectiveStatement, "Unsupported original %s", original);
-        return new RegularLeafEffectiveStatement((AbstractLeafEffectiveStatement) original, argument, flags);
+        final var orig = (AbstractLeafEffectiveStatement) original;
+        return argument.equals(orig.getDeclared().argument()) ? new EmptyLeafEffectiveStatement(orig, flags)
+            : new RegularLeafEffectiveStatement(orig, argument, flags);
     }
 
     public static LeafEffectiveStatement createLeaf(final LeafStatement declared, final QName argument, final int flags,
index a548a04d17c4c8e4dca526ee227d00cb0f8cd9ec..fd6b6b5bc3e87370623e97903a977e63e0d4c6f8 100644 (file)
@@ -18,6 +18,10 @@ public final class EmptyLeafEffectiveStatement extends AbstractLeafEffectiveStat
         super(declared, flags, substatements);
     }
 
+    public EmptyLeafEffectiveStatement(final AbstractLeafEffectiveStatement original, final int flags) {
+        super(original, flags);
+    }
+
     @Override
     public QName argument() {
         return getDeclared().argument();