Split processStatement a bit more 86/87786/1
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 13 Feb 2020 16:18:29 +0000 (17:18 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 16 Feb 2020 09:51:57 +0000 (10:51 +0100)
Split out the slow path (of allocating a statement) into a separate
method, so that the main entrypoint is more easily inlineable.

JIRA: YANGTOOLS-652
Change-Id: Iccae60e336915e06d64731e3fe4aa278cba90996
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/repo/StatementContextVisitor.java

index 781a68dd85a954715db69e9afd82adc227d1e6fb..70bff4d2ad1c2b994c5b7077bfc00858d3b31e80 100644 (file)
@@ -91,13 +91,18 @@ class StatementContextVisitor {
         return stmtDef.get(QName.create(module, localName));
     }
 
+    // Normal entry point, checks for potential resume
     private boolean processStatement(final int myOffset, final StatementContext ctx) {
         final Optional<? extends ResumedStatement> optResumed = writer.resumeStatement(myOffset);
         if (optResumed.isPresent()) {
             final ResumedStatement resumed = optResumed.get();
-            return resumed.isFullyDefined() || processStatement(ctx, resumed.getSourceReference());
+            return resumed.isFullyDefined() || doProcessStatement(ctx, resumed.getSourceReference());
         }
+        return processNewStatement(myOffset, ctx);
+    }
 
+    // Slow-path allocation of a new statement
+    private boolean processNewStatement(final int myOffset, final StatementContext ctx) {
         final String keywordTxt = verifyNotNull(ctx.getChild(KeywordContext.class, 0)).getText();
         final Token start = ctx.getStart();
         final StatementSourceReference ref = DeclarationInTextSource.atPosition(sourceName, start.getLine(),
@@ -110,10 +115,11 @@ class StatementContextVisitor {
         final ArgumentContext argumentCtx = ctx.getChild(ArgumentContext.class, 0);
         final String argument = argumentCtx == null ? null : utils.stringFromStringContext(argumentCtx, ref);
         writer.startStatement(myOffset, def, argument, ref);
-        return processStatement(ctx, ref);
+        return doProcessStatement(ctx, ref);
     }
 
-    private boolean processStatement(final StatementContext ctx, final StatementSourceReference ref) {
+    // Actual processing
+    private boolean doProcessStatement(final StatementContext ctx, final StatementSourceReference ref) {
         int childOffset = 0;
         boolean fullyDefined = true;
         if (ctx.children != null) {