Use SharedSingletonMapTemplate 18/78118/6
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 25 Nov 2018 17:21:00 +0000 (18:21 +0100)
committerRobert Varga <nite@hq.sk>
Sat, 1 Dec 2018 08:11:20 +0000 (08:11 +0000)
We know the key statically, hence we can use more efficient maps
to hold our NodeIdentifierWithPredicates. This saves some CPU cycles
as well as produces less garbage.

JIRA: MDSAL-917
Change-Id: I55b89498ab725f8aba85f8e7f1c8bb16f0fe6565
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/entityownership/EntityOwnersModel.java

index 22d5935..6451833 100644 (file)
@@ -13,6 +13,7 @@ import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controll
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.EntityType;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.Entity;
 import org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.controller.md.sal.clustering.entity.owners.rev150804.entity.owners.entity.type.entity.Candidate;
+import org.opendaylight.yangtools.util.SharedSingletonMapTemplate;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier;
 import org.opendaylight.yangtools.yang.data.api.YangInstanceIdentifier.NodeIdentifier;
@@ -49,6 +50,9 @@ public final class EntityOwnersModel {
     static final YangInstanceIdentifier ENTITY_TYPES_PATH =
             YangInstanceIdentifier.of(EntityOwners.QNAME).node(EntityType.QNAME);
 
+    private static final SharedSingletonMapTemplate<QName> NODE_KEY_TEMPLATE = SharedSingletonMapTemplate.ordered(
+        CANDIDATE_NAME_QNAME);
+
     private EntityOwnersModel() {
     }
 
@@ -65,7 +69,6 @@ public final class EntityOwnersModel {
                 .nodeWithKey(EntityType.QNAME, ENTITY_TYPE_QNAME, entityType).node(ENTITY_QNAME)
                         .nodeWithKey(ENTITY_QNAME, ENTITY_ID_QNAME, entityId).node(Candidate.QNAME)
                                 .nodeWithKey(Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName).build();
-
     }
 
     static YangInstanceIdentifier candidatePath(final YangInstanceIdentifier entityPath, final String candidateName) {
@@ -74,7 +77,7 @@ public final class EntityOwnersModel {
     }
 
     static NodeIdentifierWithPredicates candidateNodeKey(final String candidateName) {
-        return new NodeIdentifierWithPredicates(Candidate.QNAME, CANDIDATE_NAME_QNAME, candidateName);
+        return new NodeIdentifierWithPredicates(Candidate.QNAME, NODE_KEY_TEMPLATE.instantiateWithValue(candidateName));
     }
 
     static NormalizedNode<?, ?> entityOwnersWithCandidate(final String entityType,

©2013 OpenDaylight, A Linux Foundation Collaborative Project. All Rights Reserved.
OpenDaylight is a registered trademark of The OpenDaylight Project, Inc.
Linux Foundation and OpenDaylight are registered trademarks of the Linux Foundation.
Linux is a registered trademark of Linus Torvalds.