Remove AbstractExplicitGenerator.recursiveRuntimeType() 11/100111/3
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 13 Mar 2022 23:05:02 +0000 (00:05 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 14 Mar 2022 18:12:53 +0000 (19:12 +0100)
A potential identified in the bug report is repetitive creation
of the same runtime type, when it clearly should be reused.
Make sure we recognize when we are dealing with the same statement
and eliminate one Optional.map() indirection.

JIRA: MDSAL-735
Change-Id: Iaa97a04f58465b302666ca082a887fde9616282a
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-generator/src/main/java/org/opendaylight/mdsal/binding/generator/impl/reactor/AbstractExplicitGenerator.java

index 3ca83a023da644a1810f1292f44bb8a3cf01eeec..67883f3f94d382f3cb9ad94428b978e07c7ddb1b 100644 (file)
@@ -92,15 +92,11 @@ public abstract class AbstractExplicitGenerator<S extends EffectiveStatement<?,
     }
 
     final Optional<R> runtimeTypeOf(final @NonNull S stmt) {
-        return recursiveRuntimeType().map(childType -> rebaseRuntimeType(childType, stmt));
-    }
-
-    public final Optional<R> recursiveRuntimeType() {
-        AbstractExplicitGenerator<S, R> gen = this;
+        var gen = this;
         do {
             final var ret = gen.runtimeType();
             if (ret.isPresent()) {
-                return ret;
+                return Optional.of(rebaseRuntimeType(ret.orElseThrow(), stmt));
             }
 
             gen = gen.previous();