BUG-2825: use array operations to move/zero arrays 90/35390/6
authorRobert Varga <robert.varga@pantheon.sk>
Thu, 25 Feb 2016 11:27:50 +0000 (12:27 +0100)
committerGerrit Code Review <gerrit@opendaylight.org>
Thu, 25 Feb 2016 15:23:30 +0000 (15:23 +0000)
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>
model/ietf/ietf-type-util/src/main/java/org/opendaylight/mdsal/model/ietf/util/Ipv6Utils.java

index 72c8bf9c12dd603795b62fa79463d267704f239f..43c2126942e1b9591687e69a8f39641ee080d3b1 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);
+    }
 }