BUG-2825: use array operations to move/zero arrays 49/35649/5
authorRobert Varga <robert.varga@pantheon.sk>
Thu, 25 Feb 2016 11:27:50 +0000 (12:27 +0100)
committerRobert Varga <rovarga@cisco.com>
Fri, 4 Mar 2016 01:45:35 +0000 (02:45 +0100)
Instead of an open-coded loop, perform element movement and zeroing out
in two steps using System.arrayCopy() and Arrays.fill().

Change-Id: Ide8509ecba7ef0a41df4832ed4832e691cefda6c
Signed-off-by: Robert Varga <robert.varga@pantheon.sk>
(cherry picked from commit 8aa122cc53aa1686fba1abd5fdae92fa74d07bd5)

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

index 455b6cc07d74283b1d327dc0ebc14ac3ceb8431e..bd0d3220de8deaa7c381c3a710d5cf58fbc12ea6 100644 (file)
@@ -9,6 +9,7 @@ package org.opendaylight.mdsal.model.ietf.util;
 
 import com.google.common.base.Preconditions;
 import com.google.common.base.Verify;
+import java.util.Arrays;
 import javax.annotation.Nonnull;
 
 /**
@@ -126,16 +127,18 @@ final class Ipv6Utils {
 
        if (colonp != -1) {
            Verify.verify(j != INADDR6SZ, "Overrun in parsing of '%s', should not occur", addrStr);
-
-           final int n = j - colonp;
-           for (i = 1; i <= n; i++) {
-               dst[INADDR6SZ - i] = dst[j - i];
-               dst[j - i] = 0;
-           }
+           expandZeros(dst, colonp, j);
        } else {
            Verify.verify(j == INADDR6SZ, "Overrun in parsing of '%s', should not occur", addrStr);
        }
 
        return dst;
    }
+
+   private static void expandZeros(final byte[] bytes, final int where, final int filledBytes) {
+       final int tailLength = filledBytes - where;
+       final int tailOffset = INADDR6SZ - tailLength;
+       System.arraycopy(bytes, where, bytes, tailOffset, tailLength);
+       Arrays.fill(bytes, where, tailOffset, (byte)0);
+    }
 }