Speed up DataContainerCodecPrototype.get() a bit 16/81716/1
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 23 Apr 2019 09:38:33 +0000 (11:38 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 23 Apr 2019 13:43:43 +0000 (15:43 +0200)
We can use less byte code to initialize both the local handle
and the cache field.

Change-Id: I362d0125836c6d962c4366c03ba76ae244fc54e5
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit d4e362b68ea1cc5785bd6a01dff25dddb1213d81)

binding/mdsal-binding-dom-codec/src/main/java/org/opendaylight/mdsal/binding/dom/codec/impl/DataContainerCodecPrototype.java

index 9fa864d825305eb60793ff2c5d7832f38ac44a58..02c9ec1ae86e596dd3c677c792d5f6a89cad0ce2 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.binding.dom.codec.impl;
 
 import com.google.common.collect.Iterables;
 import javax.annotation.concurrent.GuardedBy;
+import org.eclipse.jdt.annotation.NonNull;
 import org.opendaylight.mdsal.binding.dom.codec.api.BindingCodecTreeNode.ChildAddressabilitySummary;
 import org.opendaylight.mdsal.binding.dom.codec.impl.NodeCodecContext.CodecContextFactory;
 import org.opendaylight.yangtools.yang.binding.DataObject;
@@ -45,7 +46,7 @@ final class DataContainerCodecPrototype<T extends WithStatus> implements NodeCon
     private final PathArgument yangArg;
     private final ChildAddressabilitySummary childAddressabilitySummary;
 
-    private volatile DataContainerCodecContext<?, T> instance = null;
+    private volatile DataContainerCodecContext<?, T> instance;
 
     @SuppressWarnings("unchecked")
     private DataContainerCodecPrototype(final Class<?> cls, final PathArgument arg, final T nodeSchema,
@@ -208,8 +209,7 @@ final class DataContainerCodecPrototype<T extends WithStatus> implements NodeCon
             synchronized (this) {
                 tmp = instance;
                 if (tmp == null) {
-                    tmp = createInstance();
-                    instance = tmp;
+                    instance = tmp = createInstance();
                 }
             }
         }
@@ -219,7 +219,7 @@ final class DataContainerCodecPrototype<T extends WithStatus> implements NodeCon
 
     @GuardedBy("this")
     @SuppressWarnings({ "rawtypes", "unchecked" })
-    private DataContainerCodecContext<?,T> createInstance() {
+    private @NonNull DataContainerCodecContext<?, T> createInstance() {
         // FIXME: make protected abstract
         if (schema instanceof ContainerSchemaNode) {
             return new ContainerNodeCodecContext(this);