Optimize if-feature statement implementations 72/90872/2
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 14:12:11 +0000 (16:12 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Thu, 2 Jul 2020 20:00:58 +0000 (22:00 +0200)
if-feature is a simple statement, optimize the memory layout of its
implementation classes.

JIRA: YANGTOOLS-1065
Change-Id: I9e2a1dbf1f32b4fdfefd965ff88fd63425bcb5d3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureEffectiveStatement.java
yang/yang-model-api/src/main/java/org/opendaylight/yangtools/yang/model/api/stmt/IfFeatureStatement.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/EmptyIfFeatureEffectiveStatement.java [moved from yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/IfFeatureEffectiveStatementImpl.java with 55% similarity]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/EmptyIfFeatureStatement.java [moved from yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/IfFeatureStatementImpl.java with 59% similarity]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/IfFeatureStatementSupport.java
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureEffectiveStatement.java [new file with mode: 0644]
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureStatement.java [new file with mode: 0644]

index 44d0b37ed0d3c7ff03f9dabf9c05562decbfde5a..9560ae4aac95e15828d871a3df458b69d3c16bff 100644 (file)
@@ -8,9 +8,14 @@
 package org.opendaylight.yangtools.yang.model.api.stmt;
 
 import com.google.common.annotations.Beta;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
 @Beta
 public interface IfFeatureEffectiveStatement extends EffectiveStatement<IfFeatureExpr, IfFeatureStatement> {
-
+    @Override
+    default StatementDefinition statementDefinition() {
+        return YangStmtMapping.IF_FEATURE;
+    }
 }
index 7fff6d9bd954cb5720632f4439fa8328fddb5f28..797cd2e3b8e88d9b6a3a539449cb97b764682559 100644 (file)
@@ -11,12 +11,19 @@ import static com.google.common.base.Verify.verifyNotNull;
 
 import com.google.common.annotations.Beta;
 import org.eclipse.jdt.annotation.NonNull;
+import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
 import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.StatementDefinition;
 
 /**
  * Represents YANG if-feature statement. The "if-feature" statement makes its parent statement conditional.
  */
 public interface IfFeatureStatement extends DeclaredStatement<IfFeatureExpr> {
+    @Override
+    default StatementDefinition statementDefinition() {
+        return YangStmtMapping.IF_FEATURE;
+    }
+
     /**
      * In YANG 1.1 (RFC7950) implementation of IfFeatureStatement, the argument is a boolean expression over feature
      * names defined by "feature" statements. Hence, add implementation to return a predicate on a collection
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -10,12 +10,11 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureExpr;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
-import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.DeclaredEffectiveStatementBase;
-import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument;
 
-final class IfFeatureEffectiveStatementImpl extends DeclaredEffectiveStatementBase<IfFeatureExpr, IfFeatureStatement>
+final class EmptyIfFeatureEffectiveStatement extends DefaultArgument<IfFeatureExpr, IfFeatureStatement>
         implements IfFeatureEffectiveStatement {
-    IfFeatureEffectiveStatementImpl(final StmtContext<IfFeatureExpr, IfFeatureStatement, ?> ctx) {
-        super(ctx);
+    EmptyIfFeatureEffectiveStatement(final IfFeatureStatement declared) {
+        super(declared);
     }
-}
\ No newline at end of file
+}
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2015 Cisco Systems, Inc. and others.  All rights reserved.
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
  *
  * This program and the accompanying materials are made available under the
  * terms of the Eclipse Public License v1.0 which accompanies this distribution,
@@ -9,11 +9,11 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature;
 
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureExpr;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractDeclaredStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument;
 import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
 
-final class IfFeatureStatementImpl extends AbstractDeclaredStatement<IfFeatureExpr> implements IfFeatureStatement {
-    IfFeatureStatementImpl(final StmtContext<IfFeatureExpr, IfFeatureStatement, ?> context) {
+final class EmptyIfFeatureStatement extends WithArgument<IfFeatureExpr> implements IfFeatureStatement {
+    EmptyIfFeatureStatement(final StmtContext<IfFeatureExpr, ?, ?> context) {
         super(context);
     }
 }
index fb952751e98befee97554ba0155d9cb3d1d7ab92..fef29a1bdee98827dac923ac24b44ce3969ddf69 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature;
 
 import static com.google.common.base.Verify.verifyNotNull;
 
+import com.google.common.collect.ImmutableList;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -17,11 +18,13 @@ import java.util.Set;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.common.YangVersion;
 import org.opendaylight.yangtools.yang.model.api.YangStmtMapping;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureEffectiveStatement;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureExpr;
 import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.BaseStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.FeatureNamespace;
-import org.opendaylight.yangtools.yang.parser.spi.meta.AbstractStatementSupport;
 import org.opendaylight.yangtools.yang.parser.spi.meta.InferenceException;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder;
 import org.opendaylight.yangtools.yang.parser.spi.meta.ModelActionBuilder.InferenceAction;
@@ -36,7 +39,7 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
 public final class IfFeatureStatementSupport
-        extends AbstractStatementSupport<IfFeatureExpr, IfFeatureStatement, IfFeatureEffectiveStatement> {
+        extends BaseStatementSupport<IfFeatureExpr, IfFeatureStatement, IfFeatureEffectiveStatement> {
     private static final Logger LOG = LoggerFactory.getLogger(IfFeatureStatementSupport.class);
     private static final SubstatementValidator SUBSTATEMENT_VALIDATOR = SubstatementValidator.builder(
         YangStmtMapping.IF_FEATURE)
@@ -92,18 +95,32 @@ public final class IfFeatureStatementSupport
     }
 
     @Override
-    public IfFeatureStatement createDeclared(final StmtContext<IfFeatureExpr, IfFeatureStatement, ?> ctx) {
-        return new IfFeatureStatementImpl(ctx);
+    protected SubstatementValidator getSubstatementValidator() {
+        return SUBSTATEMENT_VALIDATOR;
     }
 
     @Override
-    public IfFeatureEffectiveStatement createEffective(
-            final StmtContext<IfFeatureExpr, IfFeatureStatement, IfFeatureEffectiveStatement> ctx) {
-        return new IfFeatureEffectiveStatementImpl(ctx);
+    protected IfFeatureStatement createDeclared(final StmtContext<IfFeatureExpr, IfFeatureStatement, ?> ctx,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        return new RegularIfFeatureStatement(ctx, substatements);
     }
 
     @Override
-    protected SubstatementValidator getSubstatementValidator() {
-        return SUBSTATEMENT_VALIDATOR;
+    protected IfFeatureStatement createEmptyDeclared(final StmtContext<IfFeatureExpr, IfFeatureStatement, ?> ctx) {
+        return new EmptyIfFeatureStatement(ctx);
+    }
+
+    @Override
+    protected IfFeatureEffectiveStatement createEffective(
+            final StmtContext<IfFeatureExpr, IfFeatureStatement, IfFeatureEffectiveStatement> ctx,
+            final IfFeatureStatement declared, final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        return new RegularIfFeatureEffectiveStatement(declared, substatements);
+    }
+
+    @Override
+    protected IfFeatureEffectiveStatement createEmptyEffective(
+            final StmtContext<IfFeatureExpr, IfFeatureStatement, IfFeatureEffectiveStatement> ctx,
+            final IfFeatureStatement declared) {
+        return new EmptyIfFeatureEffectiveStatement(declared);
     }
 }
\ No newline at end of file
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureEffectiveStatement.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureEffectiveStatement.java
new file mode 100644 (file)
index 0000000..449b1fb
--- /dev/null
@@ -0,0 +1,23 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.EffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureEffectiveStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureExpr;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredEffectiveStatement.DefaultArgument.WithSubstatements;
+
+final class RegularIfFeatureEffectiveStatement extends WithSubstatements<IfFeatureExpr, IfFeatureStatement>
+        implements IfFeatureEffectiveStatement {
+    RegularIfFeatureEffectiveStatement(final IfFeatureStatement declared,
+            final ImmutableList<? extends EffectiveStatement<?, ?>> substatements) {
+        super(declared, substatements);
+    }
+}
diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureStatement.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/if_feature/RegularIfFeatureStatement.java
new file mode 100644 (file)
index 0000000..12f9edd
--- /dev/null
@@ -0,0 +1,22 @@
+/*
+ * Copyright (c) 2020 PANTHEON.tech, s.r.o. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.parser.rfc7950.stmt.if_feature;
+
+import com.google.common.collect.ImmutableList;
+import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureExpr;
+import org.opendaylight.yangtools.yang.model.api.stmt.IfFeatureStatement;
+import org.opendaylight.yangtools.yang.parser.rfc7950.stmt.AbstractDeclaredStatement.WithArgument.WithSubstatements;
+import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext;
+
+final class RegularIfFeatureStatement extends WithSubstatements<IfFeatureExpr> implements IfFeatureStatement {
+    RegularIfFeatureStatement(final StmtContext<IfFeatureExpr, ?, ?> context,
+            final ImmutableList<? extends DeclaredStatement<?>> substatements) {
+        super(context, substatements);
+    }
+}