Speed up NormalizedNodeSchemaUtils.detectCase() 42/95842/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 18:58:31 +0000 (20:58 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 19 Apr 2021 19:00:17 +0000 (21:00 +0200)
We are dealing with two distinct cases here to side-step
AugmentationNode mechanics. Lift the check out of the loop, which allows
us to neatly expose a method to which callers can bind at compile time.

Change-Id: Id0a80b8e77a27905c8bf5753cfdfc3e97db84f38
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java

index 15b615e616f729e903d7bba7b560517214bf7c4a..d3a8c02c343cdc655630653a885b4befafdfbe98 100644 (file)
@@ -29,10 +29,13 @@ public final class NormalizedNodeSchemaUtils {
     }
 
     public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final DataContainerChild child) {
+        if (child instanceof AugmentationNode) {
+            return detectCase(schema, (AugmentationNode) child);
+        }
+
+        final QName childId = child.getNodeType();
         for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
-            if (child instanceof AugmentationNode
-                    && belongsToCaseAugment(choiceCaseNode, (AugmentationIdentifier) child.getIdentifier())
-                    || choiceCaseNode.findDataChildByName(child.getNodeType()).isPresent()) {
+            if (choiceCaseNode.dataChildByName(childId) != null) {
                 return Optional.of(choiceCaseNode);
             }
         }
@@ -40,6 +43,16 @@ public final class NormalizedNodeSchemaUtils {
         return Optional.empty();
     }
 
+    public static Optional<CaseSchemaNode> detectCase(final ChoiceSchemaNode schema, final AugmentationNode child) {
+        final AugmentationIdentifier childId = child.getIdentifier();
+        for (final CaseSchemaNode choiceCaseNode : schema.getCases()) {
+            if (belongsToCaseAugment(choiceCaseNode, childId)) {
+                return Optional.of(choiceCaseNode);
+            }
+        }
+        return Optional.empty();
+    }
+
     private static boolean belongsToCaseAugment(final CaseSchemaNode caseNode,
             final AugmentationIdentifier childToProcess) {
         for (final AugmentationSchemaNode augmentationSchema : caseNode.getAvailableAugmentations()) {