BUG-5222: Optimize use of declared substatements 15/49815/4
authorRobert Varga <rovarga@cisco.com>
Mon, 26 Dec 2016 16:31:13 +0000 (17:31 +0100)
committerRobert Varga <rovarga@cisco.com>
Wed, 4 Jan 2017 12:47:27 +0000 (13:47 +0100)
Do not store the return in local variable, as that serves
no real purpose.

Change-Id: Iff1ae8d2d5fe6035c283c559a38fd928637cb3c6
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/AbstractDeclaredStatement.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/stmt/rfc6020/ModuleStatementSupport.java

index 6069d4b5d47d2a614dd26548ff5cf8fa3c2cc94a..3403aa3de00410e528c59edb1c4b1e2e7af53e2f 100644 (file)
@@ -43,8 +43,8 @@ public abstract class AbstractDeclaredStatement<A> implements DeclaredStatement<
          * Perform an explicit copy, because Collections2.transform() is lazily transformed and retains pointer to
          * original collection, which may contains references to mutable context.
          */
-        final Collection<StatementContextBase<?, ?, ?>> declaredSubstatements = context.declaredSubstatements();
-        substatements = ImmutableList.copyOf(Collections2.transform(declaredSubstatements, StatementContextBase::buildDeclared));
+        substatements = ImmutableList.copyOf(Collections2.transform(context.declaredSubstatements(),
+            StatementContextBase::buildDeclared));
     }
 
     protected final <S extends DeclaredStatement<?>> S firstDeclared(final Class<S> type) {
index 67dac4f06915377bc4f22cb703b99e6e50f52536..3e5589264ffc19b79c1414eb9f7e30c166196b7c 100644 (file)
@@ -240,12 +240,10 @@ public final class StmtContextUtils {
 
     private static boolean checkFeatureSupport(final StmtContext.Mutable<?, ?, ?> stmtContext,
             final Predicate<QName> isFeatureSupported) {
-        final Collection<StatementContextBase<?, ?, ?>> substatements = stmtContext.declaredSubstatements();
-
         boolean isSupported = false;
         boolean containsIfFeature = false;
-        for (final StatementContextBase<?, ?, ?> stmt : substatements) {
-            if (stmt.getPublicDefinition().equals(YangStmtMapping.IF_FEATURE)) {
+        for (final StatementContextBase<?, ?, ?> stmt : stmtContext.declaredSubstatements()) {
+            if (YangStmtMapping.IF_FEATURE.equals(stmt.getPublicDefinition())) {
                 containsIfFeature = true;
                 if (isFeatureSupported.test((QName) stmt.getStatementArgument())) {
                     isSupported = true;
index 16e45ee35d76bfdd58031c37612591692c18a696..d387a1c199f7275e1267a29dc48068bbef2e30af 100644 (file)
@@ -104,8 +104,7 @@ public class ModuleStatementSupport extends
     public void onPreLinkageDeclared(final Mutable<String, ModuleStatement, EffectiveStatement<String, ModuleStatement>> stmt) {
         final String moduleName = stmt.getStatementArgument();
 
-        final URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(),
-                NamespaceStatement.class);
+        final URI moduleNs = firstAttributeOf(stmt.declaredSubstatements(), NamespaceStatement.class);
         SourceException.throwIfNull(moduleNs, stmt.getStatementSourceReference(),
             "Namespace of the module [%s] is missing", stmt.getStatementArgument());
         stmt.addToNs(ModuleNameToNamespace.class, moduleName, moduleNs);