Do not allocate HashMap for non-augmentations 10/92810/7
authorRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Sep 2020 12:34:20 +0000 (14:34 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Wed, 30 Sep 2020 17:54:37 +0000 (19:54 +0200)
Push state allocation into the conditional for better encapsulation.

Change-Id: Icf60a259634d263d920b60f3ab55bf162cf709d8
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
binding/mdsal-binding-runtime-api/src/main/java/org/opendaylight/mdsal/binding/runtime/api/AbstractBindingRuntimeContext.java

index 96b5db7ab23d76644de9d85539e715fe8e80874e..603624cd8f69e3358b66dec2c662bcacf6569bcf 100644 (file)
@@ -235,8 +235,8 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
     @Override
     public final ImmutableMap<AugmentationIdentifier, Type> getAvailableAugmentationTypes(
             final DataNodeContainer container) {
-        final Map<AugmentationIdentifier, Type> identifierToType = new HashMap<>();
         if (container instanceof AugmentationTarget) {
+            final Map<AugmentationIdentifier, Type> identifierToType = new HashMap<>();
             final BindingRuntimeTypes types = getTypes();
             for (final AugmentationSchemaNode augment : ((AugmentationTarget) container).getAvailableAugmentations()) {
                 // Augmentation must have child nodes if is to be used with Binding classes
@@ -252,9 +252,10 @@ public abstract class AbstractBindingRuntimeContext implements BindingRuntimeCon
                     }
                 }
             }
+            return ImmutableMap.copyOf(identifierToType);
         }
 
-        return ImmutableMap.copyOf(identifierToType);
+        return ImmutableMap.of();
     }
 
     @Override