changeset 40415:256109602af0

8164189: Collectors.toSet() parallel performance improvement Reviewed-by: shade, psandoz
author tvaleev
date Thu, 18 Aug 2016 17:30:49 -0700
parents 1f4a9da41c1f
children 5d91b2fd668c
files jdk/src/java.base/share/classes/java/util/stream/Collectors.java
diffstat 1 files changed, 7 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- 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);
     }