8164189: Collectors.toSet() parallel performance improvement
Reviewed-by: shade, psandoz
--- a/jdk/src/java.base/share/classes/java/util/stream/Collectors.java Fri Aug 19 01:41:54 2016 +0300
+++ b/jdk/src/java.base/share/classes/java/util/stream/Collectors.java Thu Aug 18 17:30:49 2016 -0700
@@ -295,7 +295,13 @@
public static <T>
Collector<T, ?, Set<T>> toSet() {
return new CollectorImpl<>((Supplier<Set<T>>) HashSet::new, Set::add,
- (left, right) -> { left.addAll(right); return left; },
+ (left, right) -> {
+ if (left.size() < right.size()) {
+ right.addAll(left); return right;
+ } else {
+ left.addAll(right); return left;
+ }
+ },
CH_UNORDERED_ID);
}