From 603bb3f1c400b283e3634b45c42abd500961be0c Mon Sep 17 00:00:00 2001 From: Robert Varga Date: Mon, 25 Nov 2019 16:06:50 +0100 Subject: [PATCH] Eliminate childNodes map Both AbstractEffectiveDocumentedDataNodeContainer and AbstractEffectiveModule are subclasses of AbstractSchemaEffectiveDocumentedNode, which contains schema tree index. As all DataSchemaNodes have to strictly be a subset of the schema tree, we can ditch the dedicated index and simply perform a lookup on the schema tree followed by a check for DataSchemaNode. JIRA: YANGTOOLS-1043 Change-Id: I79d5b8ceeb6c16aef162eda9c2a8430b7a9c98f7 Signed-off-by: Robert Varga (cherry picked from commit 3a3b4422017da67c4f37c06b2e286c3a69c6d0c1) --- ...tEffectiveDocumentedDataNodeContainer.java | 8 +------- .../rfc7950/stmt/AbstractEffectiveModule.java | 6 +----- ...AbstractSchemaEffectiveDocumentedNode.java | 20 ++++++++++++++++++- 3 files changed, 21 insertions(+), 13 deletions(-) diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveDocumentedDataNodeContainer.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveDocumentedDataNodeContainer.java index e7f3cf00d0..3f472c7887 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveDocumentedDataNodeContainer.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveDocumentedDataNodeContainer.java @@ -7,9 +7,6 @@ */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt; -import static java.util.Objects.requireNonNull; - -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.util.HashSet; import java.util.LinkedHashMap; @@ -31,7 +28,6 @@ import org.opendaylight.yangtools.yang.parser.spi.meta.StmtContext; public abstract class AbstractEffectiveDocumentedDataNodeContainer> extends AbstractSchemaEffectiveDocumentedNode implements DataNodeContainer { - private final ImmutableMap childNodes; private final ImmutableSet groupings; private final ImmutableSet uses; private final ImmutableSet> typeDefinitions; @@ -68,7 +64,6 @@ public abstract class AbstractEffectiveDocumentedDataNodeContainer findDataChildByName(final QName name) { - // Child nodes are keyed by their container name, so we can do a direct lookup - return Optional.ofNullable(childNodes.get(requireNonNull(name))); + return findDataSchemaNode(name); } @Override diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java index d2da6974d1..8376d38cea 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractEffectiveModule.java @@ -12,7 +12,6 @@ import static java.util.Objects.requireNonNull; import com.google.common.annotations.Beta; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; -import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableSet; import java.net.URI; import java.util.ArrayList; @@ -71,7 +70,6 @@ public abstract class AbstractEffectiveModule deviations; private final ImmutableList extensionNodes; private final ImmutableSet identities; - private final ImmutableMap childNodes; private final ImmutableSet groupings; private final ImmutableSet uses; private final ImmutableSet> typeDefinitions; @@ -167,7 +165,6 @@ public abstract class AbstractEffectiveModule findDataChildByName(final QName name) { - // Child nodes are keyed by their container name, so we can do a direct lookup - return Optional.ofNullable(childNodes.get(requireNonNull(name))); + return findDataSchemaNode(name); } @Override diff --git a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractSchemaEffectiveDocumentedNode.java b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractSchemaEffectiveDocumentedNode.java index 6e0bd75359..f459f595a9 100644 --- a/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractSchemaEffectiveDocumentedNode.java +++ b/yang/yang-parser-rfc7950/src/main/java/org/opendaylight/yangtools/yang/parser/rfc7950/stmt/AbstractSchemaEffectiveDocumentedNode.java @@ -7,12 +7,17 @@ */ package org.opendaylight.yangtools.yang.parser.rfc7950.stmt; +import static com.google.common.base.Verify.verify; +import static java.util.Objects.requireNonNull; + import com.google.common.annotations.Beta; import com.google.common.collect.ImmutableMap; import java.util.LinkedHashMap; import java.util.Map; import java.util.Optional; import org.opendaylight.yangtools.yang.common.QName; +import org.opendaylight.yangtools.yang.model.api.DataNodeContainer; +import org.opendaylight.yangtools.yang.model.api.DataSchemaNode; import org.opendaylight.yangtools.yang.model.api.meta.DeclaredStatement; import org.opendaylight.yangtools.yang.model.api.meta.IdentifierNamespace; import org.opendaylight.yangtools.yang.model.api.stmt.CaseEffectiveStatement; @@ -41,7 +46,10 @@ public abstract class AbstractSchemaEffectiveDocumentedNode ctx) { super(ctx); - if (this instanceof SchemaTreeAwareEffectiveStatement) { + // This check is rather weird, but comes from our desire to lower memory footprint while providing both + // EffectiveStatements and SchemaNode interfaces -- which do not overlap completely where child lookups are + // concerned. This ensures that we have SchemaTree index available for use with child lookups. + if (this instanceof SchemaTreeAwareEffectiveStatement || this instanceof DataNodeContainer) { final StatementSourceReference ref = ctx.getStatementSourceReference(); final Map> schemaChildren = new LinkedHashMap<>(); streamEffectiveSubstatements(SchemaTreeEffectiveStatement.class).forEach(child -> { @@ -90,6 +98,16 @@ public abstract class AbstractSchemaEffectiveDocumentedNode findDataSchemaNode(final QName name) { + // Only DataNodeContainer subclasses should be calling this method + verify(this instanceof DataNodeContainer); + final SchemaTreeEffectiveStatement child = schemaTreeNamespace.get(requireNonNull(name)); + return child instanceof DataSchemaNode ? Optional.of((DataSchemaNode) child) : Optional.empty(); + } + private static > void putChild(final Map map, final T child, final StatementSourceReference ref, final String tree) { final QName id = child.getIdentifier(); -- 2.36.6