Optimize binding InstanceIdentifier methods 35/21135/2
authorRobert Varga <rovarga@cisco.com>
Tue, 26 May 2015 13:09:00 +0000 (15:09 +0200)
committerGerrit Code Review <gerrit@opendaylight.org>
Wed, 27 May 2015 15:17:02 +0000 (15:17 +0000)
Openflow traces show some overhead from UnmodifiableIterable. As it
turns out, we are instantiating them needlessly for internal iteration.
This stems from accessing getPathArguments() instead of pathArguments,
which are exposed precisely for this optimization.

Make sure to access pathArguments directly, eliminating this overhead.

Change-Id: I3ef053baa35c80f555b6b9f0b8813692236afa48
Signed-off-by: Robert Varga <rovarga@cisco.com>
(cherry picked from commit 96639b4fd02beb3590f62fdfc096936e71ad4a32)

yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/InstanceIdentifier.java
yang/yang-binding/src/main/java/org/opendaylight/yangtools/yang/binding/KeyedInstanceIdentifier.java

index f2744cc1b873dbc7aa56662e373cd4b83cfe4f8a..f99f3a45dea4570f6dfb5723960808c89389a3b2 100644 (file)
@@ -182,7 +182,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      * @return ToStringHelper instance which was passed in
      */
     protected ToStringHelper addToStringAttributes(final ToStringHelper toStringHelper) {
-        return toStringHelper.add("targetType", targetType).add("path", Iterables.toString(getPathArguments()));
+        return toStringHelper.add("targetType", targetType).add("path", Iterables.toString(pathArguments));
     }
 
     /**
@@ -206,10 +206,10 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      */
     public final <I extends DataObject> InstanceIdentifier<I> firstIdentifierOf(final Class<I> type) {
         int i = 1;
-        for (final PathArgument a : getPathArguments()) {
+        for (final PathArgument a : pathArguments) {
             if (type.equals(a.getType())) {
                 @SuppressWarnings("unchecked")
-                final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(Iterables.limit(getPathArguments(), i));
+                final InstanceIdentifier<I> ret = (InstanceIdentifier<I>) internalCreate(Iterables.limit(pathArguments, i));
                 return ret;
             }
 
@@ -229,7 +229,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
      *         is not present.
      */
     public final <N extends Identifiable<K> & DataObject, K extends Identifier<N>> K firstKeyOf(final Class<N> listItem, final Class<K> listKey) {
-        for (final PathArgument i : getPathArguments()) {
+        for (final PathArgument i : pathArguments) {
             if (listItem.equals(i.getType())) {
                 @SuppressWarnings("unchecked")
                 final K ret = ((IdentifiableItem<N, K>)i).getKey();
@@ -355,7 +355,7 @@ public class InstanceIdentifier<T extends DataObject> implements Path<InstanceId
     @Deprecated
     public final List<PathArgument> getPath() {
         if (legacyCache == null) {
-            legacyCache = ImmutableList.<PathArgument>copyOf(getPathArguments());
+            legacyCache = ImmutableList.<PathArgument>copyOf(pathArguments);
         }
 
         return legacyCache;
index 88ec004a5b176c76a3ae9d5ca9e795bade96553f..a69b98879fffece20cf415fc1e006df3dbb99150 100644 (file)
@@ -35,7 +35,7 @@ public class KeyedInstanceIdentifier<T extends Identifiable<K> & DataObject, K e
 
     @Override
     public final InstanceIdentifierBuilder<T> builder() {
-        return new InstanceIdentifierBuilderImpl<T>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), getPathArguments(), hashCode(), isWildcarded());
+        return new InstanceIdentifierBuilderImpl<T>(new InstanceIdentifier.IdentifiableItem<T, K>(getTargetType(), key), pathArguments, hashCode(), isWildcarded());
     }
 
     @Override