Skip to content

Commit 98c294b

Browse files
committed
Merge #498
498: FromParallelIterator and ParallelExtend Cow for String r=cuviper a=cuviper Parallel version of rust-lang/rust#41449.
2 parents f37fc75 + e2ad7a2 commit 98c294b

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/iter/extend.rs

+10
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::{ParallelExtend, IntoParallelIterator, ParallelIterator};
22

3+
use std::borrow::Cow;
34
use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet};
45
use std::hash::{BuildHasher, Hash};
56
use std::collections::LinkedList;
@@ -262,6 +263,15 @@ impl ParallelExtend<String> for String {
262263
}
263264
}
264265

266+
/// Extend a string with string slices from a parallel iterator.
267+
impl<'a> ParallelExtend<Cow<'a, str>> for String {
268+
fn par_extend<I>(&mut self, par_iter: I)
269+
where I: IntoParallelIterator<Item = Cow<'a, str>>
270+
{
271+
extend(self, par_iter, |string, list| string.reserve(str_len(list)));
272+
}
273+
}
274+
265275

266276
/// Extend a deque with items from a parallel iterator.
267277
impl<T> ParallelExtend<T> for VecDeque<T>

src/iter/from_par_iter.rs

+9
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,15 @@ impl FromParallelIterator<String> for String {
154154
}
155155
}
156156

157+
/// Collect string slices from a parallel iterator into a string.
158+
impl<'a> FromParallelIterator<Cow<'a, str>> for String {
159+
fn from_par_iter<I>(par_iter: I) -> Self
160+
where I: IntoParallelIterator<Item = Cow<'a, str>>
161+
{
162+
collect_extended(par_iter)
163+
}
164+
}
165+
157166
/// Collect an arbitrary `Cow` collection.
158167
///
159168
/// Note, the standard library only has `FromIterator` for `Cow<'a, str>` and

0 commit comments

Comments
 (0)