Fix noRev map efficiency 46/79046/3
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 25 Dec 2018 23:07:24 +0000 (00:07 +0100)
committerRobert Varga <nite@hq.sk>
Tue, 25 Dec 2018 23:52:10 +0000 (23:52 +0000)
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 <robert.varga@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/QName.java
yang/yang-parser-spi/src/main/java/org/opendaylight/yangtools/yang/parser/spi/source/QNameToStatementDefinitionMap.java

index ffdf08bb87663dd03e68b6cb36ff1520bf6f01ce..bb6ebc49a3f6ead3b2fae4b064c14e98a2c3d8fc 100644 (file)
@@ -354,7 +354,8 @@ public final class QName implements Immutable, Serializable, Comparable<QName>,
      * @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);
     }
 
     /**
index 3af0c28170cae179badd6267797dda5b828cf8b3..5ddb7d872d168002a79001543b15cb51dd130892 100644 (file)
@@ -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