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.
This commit is contained in:
Michael Schierl
2017-09-02 21:27:45 +02:00
committed by GitHub
parent f43d606f04
commit f694178ac1
+2 -6
View File
@@ -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));