From f694178ac1ddd26b1671753225a72fedfc32b12e Mon Sep 17 00:00:00 2001 From: Michael Schierl Date: Sat, 2 Sep 2017 21:27:45 +0200 Subject: [PATCH] Use correct arraycopy length The code copies 243 single adjacent element in an array using arraycopy in a loop. For copying single elements, direct array access is more performant (as it avoids the penalty of calling into native code and the JIT may detect patterns and optimize them). However, in this case, as the copied elements are adjacent, replace the whole loop with a single arraycopy call. --- src/main/java/jota/utils/Signing.java | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/main/java/jota/utils/Signing.java b/src/main/java/jota/utils/Signing.java index a1e3cdf..9119f3f 100644 --- a/src/main/java/jota/utils/Signing.java +++ b/src/main/java/jota/utils/Signing.java @@ -93,9 +93,7 @@ public class Signing { .squeeze(hash, 0, hash.length); } - for (int j = 0; j < 243; j++) { - System.arraycopy(hash, j, keyFragment, i * 243 + j, 1); - } + System.arraycopy(hash, 0, keyFragment, i * 243, 243); } return keyFragment; @@ -202,9 +200,7 @@ public class Signing { int[] digestBuffer = digest(normalizedBundleFragments[i % 3], Converter.trits(signatureFragments[i])); - for (int j = 0; j < 243; j++) { - System.arraycopy(digestBuffer, j, digests, i * 243 + j, 1); - } + System.arraycopy(digestBuffer, 0, digests, i * 243, 243); } String address = Converter.trytes(address(digests));