Skip to content

Commit 9e812fd

Browse files
authored
Merge pull request #652 from alex/optimize-rayon-collect
fixes #651 -- use rayon's optimized collect_vec_list
2 parents ab82495 + b1d9ac3 commit 9e812fd

File tree

2 files changed

+2
-16
lines changed

2 files changed

+2
-16
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ rust-version = "1.65.0"
1717
foldhash = { version = "0.2.0", default-features = false, optional = true }
1818

1919
# For external trait impls
20-
rayon = { version = "1.2", optional = true }
20+
rayon = { version = "1.9.0", optional = true }
2121
serde_core = { version = "1.0.221", default-features = false, optional = true }
2222

2323
# When built as part of libstd

src/external_trait_impls/rayon/helpers.rs

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,7 @@ use rayon::iter::{IntoParallelIterator, ParallelIterator};
66
/// Helper for collecting parallel iterators to an intermediary
77
#[allow(clippy::linkedlist)] // yes, we need linked list here for efficient appending!
88
pub(super) fn collect<I: IntoParallelIterator>(iter: I) -> (LinkedList<Vec<I::Item>>, usize) {
9-
let list = iter
10-
.into_par_iter()
11-
.fold(Vec::new, |mut vec, elem| {
12-
vec.push(elem);
13-
vec
14-
})
15-
.map(|vec| {
16-
let mut list = LinkedList::new();
17-
list.push_back(vec);
18-
list
19-
})
20-
.reduce(LinkedList::new, |mut list1, mut list2| {
21-
list1.append(&mut list2);
22-
list1
23-
});
9+
let list = iter.into_par_iter().collect_vec_list();
2410

2511
let len = list.iter().map(Vec::len).sum();
2612
(list, len)

0 commit comments

Comments
 (0)