We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 477ad98 commit 85fa6a8Copy full SHA for 85fa6a8
src/librustc_data_structures/sync.rs
@@ -19,6 +19,7 @@
19
20
use crate::owning_ref::{Erased, OwningRef};
21
use std::any::Any;
22
+use std::cmp;
23
use std::collections::HashMap;
24
use std::hash::{BuildHasher, Hash};
25
use std::marker::PhantomData;
@@ -823,3 +824,13 @@ impl<T> DerefMut for OneThread<T> {
823
824
&mut self.inner
825
}
826
827
+
828
+/// Splits the slice into parts and runs `f` on them in parallel.
829
+pub fn par_partition<'a, T: Sync, R: Send>(
830
+ slice: &'a [T],
831
+ parts: usize,
832
+ f: impl Fn(&'a [T]) -> R + Sync,
833
+) -> Vec<R> {
834
+ let chunks: Vec<_> = slice.chunks(cmp::max((slice.len() + parts - 1) / parts, 1)).collect();
835
+ par_map(chunks, |chunk| f(chunk))
836
+}
0 commit comments