From: Robert Varga Date: Tue, 25 Dec 2018 23:07:24 +0000 (+0100) Subject: Fix noRev map efficiency X-Git-Tag: v2.1.7~16 X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=commitdiff_plain;h=7afc50ff5a4485c4409045165385464ea246f4bc;p=yangtools.git Fix noRev map efficiency QName.getRevision() always returns non-null, which means we are always taking the slow version of this branch, as correctly flagged by Eclipse. Furthermore we can use QName.withoutRevision() to side-step QName's localName validation, as the local name is known to have already been checked. Change-Id: I7be3b8053ab3dbddfdf9cf12f8754a307127a8b3 Signed-off-by: Robert Varga --- diff --git a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java index ffdf08bb87..bb6ebc49a3 100644 --- a/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java +++ b/yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java @@ -354,7 +354,8 @@ public final class QName implements Immutable, Serializable, Comparable, * @return a QName with the same namespace and local name, but with no revision. */ public @NonNull QName withoutRevision() { - return getRevision().isPresent() ? new QName(module.withoutRevision(), localName) : this; + final QNameModule newModule; + return (newModule = module.withoutRevision()) == module ? this : new QName(newModule, localName); } /** diff --git a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java index 3af0c28170..5ddb7d872d 100644 --- a/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java +++ b/yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java @@ -55,13 +55,8 @@ public class QNameToStatementDefinitionMap implements QNameToStatementDefinition } private void putNoRev(final QName qname, final StatementSupport support) { - final QName norev; - if (qname.getRevision() != null) { - norev = QName.create(qname.getNamespace(), qname.getLocalName()).intern(); - } else { - norev = qname; - } - noRevQNameToSupport.put(norev, support); + final QName norev = qname.withoutRevision(); + noRevQNameToSupport.put(norev != qname ? norev.intern() : qname, support); } @Override