Skip to content

Commit

Permalink
Implement custom toArray function, some of our code reuses the underl…
Browse files Browse the repository at this point in the history
…ying array and so the out-of-the box solution doesn't work as expected.
  • Loading branch information
johnmay committed Mar 15, 2019
1 parent a339734 commit 2e4ceab
Showing 1 changed file with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import org.openscience.cdk.interfaces.IChemObject;
import org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer;

import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;

Expand Down Expand Up @@ -352,7 +353,14 @@ public Iterator<int[]> iterator() {
* @return array of mappings
*/
public int[][] toArray() {
return Iterables.toArray(iterable, int[].class);
int[][] res = new int[14][];
int size = 0;
for (int[] map : this) {
if (size == res.length)
res = Arrays.copyOf(res, size + (size >> 1));
res[size++] = map.clone();
}
return Arrays.copyOf(res, size);
}

/**
Expand Down

0 comments on commit 2e4ceab

Please sign in to comment.