Peel predicate identifiers 54/93354/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 25 Oct 2020 22:03:48 +0000 (23:03 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 25 Oct 2020 22:10:31 +0000 (23:10 +0100)
Most of the time we will be treated with simple predicates, peel
them off, so we do not end up iterating.

JIRA: MDSAL-605
Change-Id: I1864c33c5aa34cd3a58171f8cfbe729dd325fb35
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
dom/mdsal-dom-spi/src/main/java/org/opendaylight/mdsal/dom/spi/query/DOMQueryEvaluator.java

index 7e20375a62a2ea59befdcffbb115f1b900df5a43..12df752e9d7aad26d471e29d7dc847c60c17b3cf 100644 (file)
@@ -116,7 +116,17 @@ public final class DOMQueryEvaluator {
 
     private static boolean matches(final NormalizedNode<?, ?> data, final DOMQuery query) {
         for (DOMQueryPredicate pred : query.getPredicates()) {
-            if (!pred.test(NormalizedNodes.findNode(data, pred.getPath()).orElse(null))) {
+            // Okay, now we need to deal with predicates, but do it in a smart fashion, so we do not end up iterating
+            // all over the place. Typically we will be matching just a leaf.
+            final YangInstanceIdentifier path = pred.getPath();
+            final Optional<NormalizedNode<?, ?>> node;
+            if (path.coerceParent().isEmpty()) {
+                node = NormalizedNodes.getDirectChild(data, path.getLastPathArgument());
+            } else {
+                node = NormalizedNodes.findNode(data, path);
+            }
+
+            if (!pred.test(node.orElse(null))) {
                 return false;
             }
         }