Do not instantiate objects for hash values
[yangtools.git] / yang / yang-data-api / src / main / java / org / opendaylight / yangtools / yang / data / api / YangInstanceIdentifier.java
index 4488ac32c27d937fc6bc92f19d687ab782289b4e..7a7ce6c28ae91e09ec43c4e34ba2fb10a4407fcb 100644 (file)
@@ -367,11 +367,10 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
     }
 
     private static abstract class AbstractPathArgument implements PathArgument {
-        private static final AtomicReferenceFieldUpdater<AbstractPathArgument, Integer> HASH_UPDATER =
-                AtomicReferenceFieldUpdater.newUpdater(AbstractPathArgument.class, Integer.class, "hash");
         private static final long serialVersionUID = -4546547994250849340L;
         private final QName nodeType;
-        private volatile transient Integer hash = null;
+        private transient int hashValue;
+        private volatile transient boolean hashGuard = false;
 
         protected AbstractPathArgument(final QName nodeType) {
             this.nodeType = Preconditions.checkNotNull(nodeType);
@@ -393,13 +392,12 @@ public final class YangInstanceIdentifier implements Path<YangInstanceIdentifier
 
         @Override
         public final int hashCode() {
-            Integer ret = hash;
-            if (ret == null) {
-                ret = hashCodeImpl();
-                HASH_UPDATER.lazySet(this, ret);
+            if (!hashGuard) {
+                hashValue = hashCodeImpl();
+                hashGuard = true;
             }
 
-            return ret;
+            return hashValue;
         }
 
         @Override