Remove a search-before-remove on ArrayList 38/29138/1
authorRobert Varga <rovarga@cisco.com>
Mon, 2 Nov 2015 14:21:19 +0000 (15:21 +0100)
committerRobert Varga <rovarga@cisco.com>
Mon, 2 Nov 2015 14:29:05 +0000 (15:29 +0100)
There is no need to make the removal conditional on presence. This
forces two linear searches of the list, instead of just one.

Change-Id: I3d3fb23ac02e95433cc17ccee119dbb1392cef42
Signed-off-by: Robert Varga <rovarga@cisco.com>
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangStatementParserListenerImpl.java

index 58aa60c1671e7a80ec4643db113dab28f10e2f70..95176b1955edb44211e0e7ab8995e2aac654bb65 100644 (file)
@@ -40,7 +40,7 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
     private QNameToStatementDefinition stmtDef;
     private PrefixToModule prefixes;
     private final List<String> toBeSkipped = new ArrayList<>();
-    private boolean isType = false;
+    private final boolean isType = false;
     private static final Logger LOG = LoggerFactory.getLogger(YangStatementParserListenerImpl.class);
 
     public YangStatementParserListenerImpl(final String sourceName) {
@@ -111,9 +111,9 @@ public class YangStatementParserListenerImpl extends YangStatementParserBaseList
                     && toBeSkipped.isEmpty()) {
                 writer.endStatement(ref);
             }
-            if (toBeSkipped.contains(statementName)) {
-                toBeSkipped.remove(statementName);
-            }
+
+            // No-op if the statement is not on the list
+            toBeSkipped.remove(statementName);
         } catch (SourceException e) {
             LOG.warn(e.getMessage(), e);
         }