Speed up StmtContextUtils.getModuleQNameByPrefix() 22/93922/1
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 25 Nov 2020 02:34:26 +0000 (03:34 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 25 Nov 2020 02:35:17 +0000 (03:35 +0100)
We are looking up root twice here. Cache the lookup for reuse,
skipping one traversal.

Change-Id: I4ead06fa82b2ef822cbee0a2761bd90674bc1676
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/meta/StmtContextUtils.java

index fb387d4b253753cab2bd62614de3370d9324b810..aadf22441be765ab15949e8d3e7dd83d6446f7f8 100644 (file)
@@ -588,14 +588,13 @@ public final class StmtContextUtils {
     }
 
     public static QNameModule getModuleQNameByPrefix(final StmtContext<?, ?, ?> ctx, final String prefix) {
-        final StmtContext<?, ?, ?> importedModule = ctx.getRoot().getFromNamespace(ImportPrefixToModuleCtx.class,
-            prefix);
+        final StmtContext<?, ?, ?> root = ctx.getRoot();
+        final StmtContext<?, ?, ?> importedModule = root.getFromNamespace(ImportPrefixToModuleCtx.class, prefix);
         final QNameModule qnameModule = ctx.getFromNamespace(ModuleCtxToModuleQName.class, importedModule);
         if (qnameModule != null) {
             return qnameModule;
         }
 
-        final StmtContext<?, ?, ?> root = ctx.getRoot();
         if (root.producesDeclared(SubmoduleStatement.class)) {
             final String moduleName = root.getFromNamespace(BelongsToPrefixToModuleName.class, prefix);
             return ctx.getFromNamespace(ModuleNameToModuleQName.class, moduleName);