Improve AbstractPathArgument.hashCodeImpl() 46/82346/7
authorRobert Varga <robert.varga@pantheon.tech>
Thu, 30 May 2019 22:23:04 +0000 (00:23 +0200)
committerRobert Varga <nite@hq.sk>
Wed, 15 Jan 2020 11:09:01 +0000 (11:09 +0000)
Current computation of hashCode() introduces needless computation,
just for the sake of the computation.

This patch changes the hashCode() algorithm and removes increment:

    QName.hashCode() + 31

which has no real value to how hashCodeImpl() operates. While
we're in the area, we propagate useless invariants.

Change-Id: Ib18518013774673603268ad747883d67b5d2bbf3
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-data-api/src/main/java/org/opendaylight/yangtools/yang/data/api/YangInstanceIdentifier.java

index d02b7bc01e9a0a13baf3e2f680311e21994f568f..35322b8cc158e15475b7b2e8280462e7fed965f9 100644 (file)
@@ -491,7 +491,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
         }
 
         protected int hashCodeImpl() {
-            return 31 + getNodeType().hashCode();
+            return nodeType.hashCode();
         }
 
         @Override
@@ -865,10 +865,7 @@ public abstract class YangInstanceIdentifier implements Path<YangInstanceIdentif
 
         @Override
         protected int hashCodeImpl() {
-            final int prime = 31;
-            int result = super.hashCodeImpl();
-            result = prime * result + YangInstanceIdentifier.hashCode(value);
-            return result;
+            return 31 * super.hashCodeImpl() + YangInstanceIdentifier.hashCode(value);
         }
 
         @Override