From: Robert Varga Date: Mon, 19 Apr 2021 18:58:31 +0000 (+0200) Subject: Speed up NormalizedNodeSchemaUtils.detectCase() X-Git-Tag: v7.0.0~43 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=922e1166980522d3aec8afa39fc06ab490fae15d;p=yangtools.git Speed up NormalizedNodeSchemaUtils.detectCase() 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 --- diff --git a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java index 15b615e616..d3a8c02c34 100644 --- a/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java +++ b/yang/yang-data-util/src/main/java/org/opendaylight/yangtools/yang/data/util/NormalizedNodeSchemaUtils.java @@ -29,10 +29,13 @@ public final class NormalizedNodeSchemaUtils { } public static Optional 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 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()) {