make unionUnsorted 5-10% faster for lists with 100k elements

This commit is contained in:
2018-01-21 19:55:25 +01:00
parent 5515523100
commit 8ee6118854

View File

@@ -1062,14 +1062,14 @@ public final class IntList implements Serializable, Cloneable {
}
private static IntList unionUnsorted(final IntList a, final IntList b) {
// TODO use a more efficient algorithm. Especially the removeIf is too
// expensive, because of all the method calls
final IntList result;
result = new IntList(a.size() + b.size());
result.addAll(a);
result.addAll(b);
result.sort();
result.removeIf((value, index) -> index > 0 && result.get(index) == result.get(index - 1));
return result;
// TODO use a more efficient algorithm. The sort operations make this 10 times
// slower than unionSorted
final IntList aSorted = new IntList(a);
aSorted.parallelSort();
final IntList bSorted = new IntList(b);
bSorted.parallelSort();
return unionSorted(aSorted, bSorted);
}
}