Eliminate shift variable 67/86767/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 22:36:21 +0000 (23:36 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 6 Jan 2020 22:37:52 +0000 (23:37 +0100)
We do not need to track shift amount, as we can can just shift
the entire previous result, leading to more invariants in the loop.

JIRA: MDSAL-509
Change-Id: I13a108be27cac2fe4498952f3f05437927c999c0
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
(cherry picked from commit 4b26656c945b9af5e67d28d10b014b0ed37cc510)

model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/Ipv4Utils.java

index 66a94ee09e658f49a0bed6eaad780f1e0c74d421..847b1914be2d5cde08e9c87e7ed925ec6925a208 100644 (file)
@@ -39,17 +39,16 @@ final class Ipv4Utils {
     static int addressBits(final String str, final int limit) {
         int prev = 0;
         int current = 0;
-        for (int i = 0, shift = 24; i < limit; ++i) {
+        for (int i = 0; i < limit; ++i) {
             final char c = str.charAt(i);
             if (c == '.') {
-                prev |= current << shift;
-                shift -= 8;
+                prev = prev << 8 | current;
                 current = 0;
             } else {
                 current = 10 * current + c - '0';
             }
         }
-        return prev | current;
+        return prev << 8 | current;
     }
 
     static byte @NonNull[] addressBytes(final String str, final int limit) {