From 8ee6118854e88ccbaf185ff324f8df78873b35c1 Mon Sep 17 00:00:00 2001 From: Andreas Huber Date: Sun, 21 Jan 2018 19:55:25 +0100 Subject: [PATCH] make unionUnsorted 5-10% faster for lists with 100k elements --- .../java/org/lucares/collections/IntList.java | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java index af0e586..7a7e375 100644 --- a/primitiveCollections/src/main/java/org/lucares/collections/IntList.java +++ b/primitiveCollections/src/main/java/org/lucares/collections/IntList.java @@ -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); } }