Remove unneeded masking in Uint{8,16}.valueOf() 76/84476/1
authorRobert Varga <robert.varga@pantheon.tech>
Sun, 15 Sep 2019 17:31:20 +0000 (19:31 +0200)
committerRobert Varga <robert.varga@pantheon.tech>
Sun, 15 Sep 2019 17:31:20 +0000 (19:31 +0200)
As we are checking the range of the input, we can just narrow input
value, saving us a few instructions in the process.

Change-Id: I2ff52b1a75565da76804e4f02114249200e7d841
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint16.java
yang/yang-common/src/main/java/org/opendaylight/yangtools/yang/common/Uint8.java

index 3efddca331c640841d8464367fe8e6e4215e3ac8..61701fce1727843e86c4853c48fdaca624d8a552 100644 (file)
@@ -138,7 +138,7 @@ public class Uint16 extends Number implements CanonicalValue<Uint16> {
      */
     public static Uint16 valueOf(final int intVal) {
         UintConversions.checkRange(intVal, MAX_VALUE_INT, MAX_VALUE_STR);
-        return instanceFor((short)(intVal & 0xffff));
+        return instanceFor((short)intVal);
     }
 
     /**
@@ -151,7 +151,7 @@ public class Uint16 extends Number implements CanonicalValue<Uint16> {
      */
     public static Uint16 valueOf(final long longVal) {
         UintConversions.checkRange(longVal, MAX_VALUE_INT, MAX_VALUE_STR);
-        return instanceFor((short)(longVal & 0xffff));
+        return instanceFor((short)longVal);
     }
 
     /**
index a158a045d455323e93e0750ae168074573a27b42..b4421fca6597515e510ca221ffd35a98e9a400d4 100644 (file)
@@ -108,7 +108,7 @@ public class Uint8 extends Number implements CanonicalValue<Uint8> {
      */
     public static Uint8 valueOf(final short shortVal) {
         UintConversions.checkRange(shortVal, MAX_VALUE_SHORT, MAX_VALUE_STR);
-        return instanceFor((byte)(shortVal & 0xff));
+        return instanceFor((byte)shortVal);
     }
 
     /**
@@ -120,7 +120,7 @@ public class Uint8 extends Number implements CanonicalValue<Uint8> {
      */
     public static Uint8 valueOf(final int intVal) {
         UintConversions.checkRange(intVal, MAX_VALUE_SHORT, MAX_VALUE_STR);
-        return instanceFor((byte)(intVal & 0xff));
+        return instanceFor((byte)intVal);
     }
 
     /**
@@ -133,7 +133,7 @@ public class Uint8 extends Number implements CanonicalValue<Uint8> {
      */
     public static Uint8 valueOf(final long longVal) {
         UintConversions.checkRange(longVal, MAX_VALUE_SHORT, MAX_VALUE_STR);
-        return instanceFor((byte)(longVal & 0xff));
+        return instanceFor((byte)longVal);
     }
 
     /**