Avoid copying from Array to list and back

As Java's Lists use boxed Integers, we try to avoid the memory
consumption, GC pressure and time overhead caused by copying an int[]
into a List<Integer> and back again.
This commit is contained in:
Michael Schierl 2017-09-07 22:13:26 +02:00
parent 53df67d490
commit c4535aefbe

View File

@ -54,29 +54,16 @@ public class Signing {
curl.reset();
curl.absorb(seed, 0, seed.length);
final List<Integer> key = new ArrayList<>();
int[] buffer = new int[seed.length];
final int[] key = new int[length * seed.length * 27];
int offset = 0;
while (length-- > 0) {
for (int i = 0; i < 27; i++) {
curl.squeeze(buffer, offset, buffer.length);
for (int j = 0; j < 243; j++) {
key.add(buffer[j]);
}
curl.squeeze(key, offset, seed.length);
offset += seed.length;
}
}
return to(key);
}
private int[] to(List<Integer> key) {
int a[] = new int[key.size()];
int i = 0;
for (Integer v : key) {
a[i++] = v;
}
return a;
return key;
}
public int[] signatureFragment(int[] normalizedBundleFragment, int[] keyFragment) {