/rust/registry/src/index.crates.io-1949cf8c6b5b557f/rayon-1.11.0/src/iter/extend.rs
Line | Count | Source |
1 | | use super::noop::NoopConsumer; |
2 | | use super::plumbing::{Consumer, Folder, Reducer, UnindexedConsumer}; |
3 | | use super::{IntoParallelIterator, ParallelExtend, ParallelIterator}; |
4 | | |
5 | | use either::Either; |
6 | | use std::borrow::Cow; |
7 | | use std::collections::LinkedList; |
8 | | use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; |
9 | | use std::collections::{BinaryHeap, VecDeque}; |
10 | | use std::ffi::{OsStr, OsString}; |
11 | | use std::hash::{BuildHasher, Hash}; |
12 | | |
13 | | /// Performs a generic `par_extend` by collecting to a `LinkedList<Vec<_>>` in |
14 | | /// parallel, then extending the collection sequentially. |
15 | | macro_rules! extend { |
16 | | ($self:ident, $par_iter:ident) => { |
17 | | extend!($self <- fast_collect($par_iter)) |
18 | | }; |
19 | | ($self:ident <- $vecs:expr) => { |
20 | | match $vecs { |
21 | | Either::Left(vec) => $self.extend(vec), |
22 | | Either::Right(list) => { |
23 | | for vec in list { |
24 | | $self.extend(vec); |
25 | | } |
26 | | } |
27 | | } |
28 | | }; |
29 | | } |
30 | | macro_rules! extend_reserved { |
31 | | ($self:ident, $par_iter:ident, $len:ident) => { |
32 | | let vecs = fast_collect($par_iter); |
33 | | $self.reserve($len(&vecs)); |
34 | | extend!($self <- vecs) |
35 | | }; |
36 | | ($self:ident, $par_iter:ident) => { |
37 | | extend_reserved!($self, $par_iter, len) |
38 | | }; |
39 | | } |
40 | | |
41 | | /// Computes the total length of a `fast_collect` result. |
42 | 0 | fn len<T>(vecs: &Either<Vec<T>, LinkedList<Vec<T>>>) -> usize { |
43 | 0 | match vecs { |
44 | 0 | Either::Left(vec) => vec.len(), |
45 | 0 | Either::Right(list) => list.iter().map(Vec::len).sum(), |
46 | | } |
47 | 0 | } |
48 | | |
49 | | /// Computes the total string length of a `fast_collect` result. |
50 | 0 | fn string_len<T: AsRef<str>>(vecs: &Either<Vec<T>, LinkedList<Vec<T>>>) -> usize { |
51 | 0 | let strs = match vecs { |
52 | 0 | Either::Left(vec) => Either::Left(vec.iter()), |
53 | 0 | Either::Right(list) => Either::Right(list.iter().flatten()), |
54 | | }; |
55 | 0 | strs.map(AsRef::as_ref).map(str::len).sum() |
56 | 0 | } |
57 | | |
58 | | /// Computes the total OS-string length of a `fast_collect` result. |
59 | 0 | fn osstring_len<T: AsRef<OsStr>>(vecs: &Either<Vec<T>, LinkedList<Vec<T>>>) -> usize { |
60 | 0 | let osstrs = match vecs { |
61 | 0 | Either::Left(vec) => Either::Left(vec.iter()), |
62 | 0 | Either::Right(list) => Either::Right(list.iter().flatten()), |
63 | | }; |
64 | 0 | osstrs.map(AsRef::as_ref).map(OsStr::len).sum() |
65 | 0 | } |
66 | | |
67 | 0 | pub(super) fn fast_collect<I, T>(pi: I) -> Either<Vec<T>, LinkedList<Vec<T>>> |
68 | 0 | where |
69 | 0 | I: IntoParallelIterator<Item = T>, |
70 | 0 | T: Send, |
71 | | { |
72 | 0 | let par_iter = pi.into_par_iter(); |
73 | 0 | match par_iter.opt_len() { |
74 | 0 | Some(len) => { |
75 | | // Pseudo-specialization. See impl of ParallelExtend for Vec for more details. |
76 | 0 | let mut vec = Vec::new(); |
77 | 0 | super::collect::special_extend(par_iter, len, &mut vec); |
78 | 0 | Either::Left(vec) |
79 | | } |
80 | 0 | None => Either::Right(par_iter.drive_unindexed(ListVecConsumer)), |
81 | | } |
82 | 0 | } |
83 | | |
84 | | struct ListVecConsumer; |
85 | | |
86 | | struct ListVecFolder<T> { |
87 | | vec: Vec<T>, |
88 | | } |
89 | | |
90 | | impl<T: Send> Consumer<T> for ListVecConsumer { |
91 | | type Folder = ListVecFolder<T>; |
92 | | type Reducer = ListReducer; |
93 | | type Result = LinkedList<Vec<T>>; |
94 | | |
95 | 0 | fn split_at(self, _index: usize) -> (Self, Self, Self::Reducer) { |
96 | 0 | (Self, Self, ListReducer) |
97 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<alloc::vec::Vec<u8>>>::split_at Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<rav1e::stats::EncoderStats>>::split_at Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<_>>::split_at |
98 | | |
99 | 0 | fn into_folder(self) -> Self::Folder { |
100 | 0 | ListVecFolder { vec: Vec::new() } |
101 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<alloc::vec::Vec<u8>>>::into_folder Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<rav1e::stats::EncoderStats>>::into_folder Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<_>>::into_folder |
102 | | |
103 | 0 | fn full(&self) -> bool { |
104 | 0 | false |
105 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<alloc::vec::Vec<u8>>>::full Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<rav1e::stats::EncoderStats>>::full Unexecuted instantiation: <rayon::iter::extend::ListVecConsumer as rayon::iter::plumbing::Consumer<_>>::full |
106 | | } |
107 | | |
108 | | impl<T: Send> UnindexedConsumer<T> for ListVecConsumer { |
109 | 0 | fn split_off_left(&self) -> Self { |
110 | 0 | Self |
111 | 0 | } |
112 | | |
113 | 0 | fn to_reducer(&self) -> Self::Reducer { |
114 | 0 | ListReducer |
115 | 0 | } |
116 | | } |
117 | | |
118 | | impl<T> Folder<T> for ListVecFolder<T> { |
119 | | type Result = LinkedList<Vec<T>>; |
120 | | |
121 | 0 | fn consume(mut self, item: T) -> Self { |
122 | 0 | self.vec.push(item); |
123 | 0 | self |
124 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<alloc::vec::Vec<u8>> as rayon::iter::plumbing::Folder<alloc::vec::Vec<u8>>>::consume Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<rav1e::stats::EncoderStats> as rayon::iter::plumbing::Folder<rav1e::stats::EncoderStats>>::consume Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<_> as rayon::iter::plumbing::Folder<_>>::consume |
125 | | |
126 | 0 | fn consume_iter<I>(mut self, iter: I) -> Self |
127 | 0 | where |
128 | 0 | I: IntoIterator<Item = T>, |
129 | | { |
130 | 0 | self.vec.extend(iter); |
131 | 0 | self |
132 | 0 | } |
133 | | |
134 | 0 | fn complete(self) -> Self::Result { |
135 | 0 | let mut list = LinkedList::new(); |
136 | 0 | if !self.vec.is_empty() { |
137 | 0 | list.push_back(self.vec); |
138 | 0 | } |
139 | 0 | list |
140 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<alloc::vec::Vec<u8>> as rayon::iter::plumbing::Folder<alloc::vec::Vec<u8>>>::complete Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<rav1e::stats::EncoderStats> as rayon::iter::plumbing::Folder<rav1e::stats::EncoderStats>>::complete Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<_> as rayon::iter::plumbing::Folder<_>>::complete |
141 | | |
142 | 0 | fn full(&self) -> bool { |
143 | 0 | false |
144 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<alloc::vec::Vec<u8>> as rayon::iter::plumbing::Folder<alloc::vec::Vec<u8>>>::full Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<rav1e::stats::EncoderStats> as rayon::iter::plumbing::Folder<rav1e::stats::EncoderStats>>::full Unexecuted instantiation: <rayon::iter::extend::ListVecFolder<_> as rayon::iter::plumbing::Folder<_>>::full |
145 | | } |
146 | | |
147 | | /// Extends a binary heap with items from a parallel iterator. |
148 | | impl<T> ParallelExtend<T> for BinaryHeap<T> |
149 | | where |
150 | | T: Ord + Send, |
151 | | { |
152 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
153 | 0 | where |
154 | 0 | I: IntoParallelIterator<Item = T>, |
155 | | { |
156 | 0 | extend_reserved!(self, par_iter); |
157 | 0 | } |
158 | | } |
159 | | |
160 | | /// Extends a binary heap with copied items from a parallel iterator. |
161 | | impl<'a, T> ParallelExtend<&'a T> for BinaryHeap<T> |
162 | | where |
163 | | T: 'a + Copy + Ord + Send + Sync, |
164 | | { |
165 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
166 | 0 | where |
167 | 0 | I: IntoParallelIterator<Item = &'a T>, |
168 | | { |
169 | 0 | extend_reserved!(self, par_iter); |
170 | 0 | } |
171 | | } |
172 | | |
173 | | /// Extends a B-tree map with items from a parallel iterator. |
174 | | impl<K, V> ParallelExtend<(K, V)> for BTreeMap<K, V> |
175 | | where |
176 | | K: Ord + Send, |
177 | | V: Send, |
178 | | { |
179 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
180 | 0 | where |
181 | 0 | I: IntoParallelIterator<Item = (K, V)>, |
182 | | { |
183 | 0 | extend!(self, par_iter); |
184 | 0 | } |
185 | | } |
186 | | |
187 | | /// Extends a B-tree map with copied items from a parallel iterator. |
188 | | impl<'a, K: 'a, V: 'a> ParallelExtend<(&'a K, &'a V)> for BTreeMap<K, V> |
189 | | where |
190 | | K: Copy + Ord + Send + Sync, |
191 | | V: Copy + Send + Sync, |
192 | | { |
193 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
194 | 0 | where |
195 | 0 | I: IntoParallelIterator<Item = (&'a K, &'a V)>, |
196 | | { |
197 | 0 | extend!(self, par_iter); |
198 | 0 | } |
199 | | } |
200 | | |
201 | | /// Extends a B-tree set with items from a parallel iterator. |
202 | | impl<T> ParallelExtend<T> for BTreeSet<T> |
203 | | where |
204 | | T: Ord + Send, |
205 | | { |
206 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
207 | 0 | where |
208 | 0 | I: IntoParallelIterator<Item = T>, |
209 | | { |
210 | 0 | extend!(self, par_iter); |
211 | 0 | } |
212 | | } |
213 | | |
214 | | /// Extends a B-tree set with copied items from a parallel iterator. |
215 | | impl<'a, T> ParallelExtend<&'a T> for BTreeSet<T> |
216 | | where |
217 | | T: 'a + Copy + Ord + Send + Sync, |
218 | | { |
219 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
220 | 0 | where |
221 | 0 | I: IntoParallelIterator<Item = &'a T>, |
222 | | { |
223 | 0 | extend!(self, par_iter); |
224 | 0 | } |
225 | | } |
226 | | |
227 | | /// Extends a hash map with items from a parallel iterator. |
228 | | impl<K, V, S> ParallelExtend<(K, V)> for HashMap<K, V, S> |
229 | | where |
230 | | K: Eq + Hash + Send, |
231 | | V: Send, |
232 | | S: BuildHasher + Send, |
233 | | { |
234 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
235 | 0 | where |
236 | 0 | I: IntoParallelIterator<Item = (K, V)>, |
237 | | { |
238 | | // See the map_collect benchmarks in rayon-demo for different strategies. |
239 | 0 | extend_reserved!(self, par_iter); |
240 | 0 | } |
241 | | } |
242 | | |
243 | | /// Extends a hash map with copied items from a parallel iterator. |
244 | | impl<'a, K: 'a, V: 'a, S> ParallelExtend<(&'a K, &'a V)> for HashMap<K, V, S> |
245 | | where |
246 | | K: Copy + Eq + Hash + Send + Sync, |
247 | | V: Copy + Send + Sync, |
248 | | S: BuildHasher + Send, |
249 | | { |
250 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
251 | 0 | where |
252 | 0 | I: IntoParallelIterator<Item = (&'a K, &'a V)>, |
253 | | { |
254 | 0 | extend_reserved!(self, par_iter); |
255 | 0 | } |
256 | | } |
257 | | |
258 | | /// Extends a hash set with items from a parallel iterator. |
259 | | impl<T, S> ParallelExtend<T> for HashSet<T, S> |
260 | | where |
261 | | T: Eq + Hash + Send, |
262 | | S: BuildHasher + Send, |
263 | | { |
264 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
265 | 0 | where |
266 | 0 | I: IntoParallelIterator<Item = T>, |
267 | | { |
268 | 0 | extend_reserved!(self, par_iter); |
269 | 0 | } |
270 | | } |
271 | | |
272 | | /// Extends a hash set with copied items from a parallel iterator. |
273 | | impl<'a, T, S> ParallelExtend<&'a T> for HashSet<T, S> |
274 | | where |
275 | | T: 'a + Copy + Eq + Hash + Send + Sync, |
276 | | S: BuildHasher + Send, |
277 | | { |
278 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
279 | 0 | where |
280 | 0 | I: IntoParallelIterator<Item = &'a T>, |
281 | | { |
282 | 0 | extend_reserved!(self, par_iter); |
283 | 0 | } |
284 | | } |
285 | | |
286 | | /// Extends a linked list with items from a parallel iterator. |
287 | | impl<T> ParallelExtend<T> for LinkedList<T> |
288 | | where |
289 | | T: Send, |
290 | | { |
291 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
292 | 0 | where |
293 | 0 | I: IntoParallelIterator<Item = T>, |
294 | | { |
295 | 0 | let mut list = par_iter.into_par_iter().drive_unindexed(ListConsumer); |
296 | 0 | self.append(&mut list); |
297 | 0 | } |
298 | | } |
299 | | |
300 | | /// Extends a linked list with copied items from a parallel iterator. |
301 | | impl<'a, T> ParallelExtend<&'a T> for LinkedList<T> |
302 | | where |
303 | | T: 'a + Copy + Send + Sync, |
304 | | { |
305 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
306 | 0 | where |
307 | 0 | I: IntoParallelIterator<Item = &'a T>, |
308 | | { |
309 | 0 | self.par_extend(par_iter.into_par_iter().copied()) |
310 | 0 | } |
311 | | } |
312 | | |
313 | | struct ListConsumer; |
314 | | |
315 | | struct ListFolder<T> { |
316 | | list: LinkedList<T>, |
317 | | } |
318 | | |
319 | | struct ListReducer; |
320 | | |
321 | | impl<T: Send> Consumer<T> for ListConsumer { |
322 | | type Folder = ListFolder<T>; |
323 | | type Reducer = ListReducer; |
324 | | type Result = LinkedList<T>; |
325 | | |
326 | 0 | fn split_at(self, _index: usize) -> (Self, Self, Self::Reducer) { |
327 | 0 | (Self, Self, ListReducer) |
328 | 0 | } |
329 | | |
330 | 0 | fn into_folder(self) -> Self::Folder { |
331 | 0 | ListFolder { |
332 | 0 | list: LinkedList::new(), |
333 | 0 | } |
334 | 0 | } |
335 | | |
336 | 0 | fn full(&self) -> bool { |
337 | 0 | false |
338 | 0 | } |
339 | | } |
340 | | |
341 | | impl<T: Send> UnindexedConsumer<T> for ListConsumer { |
342 | 0 | fn split_off_left(&self) -> Self { |
343 | 0 | Self |
344 | 0 | } |
345 | | |
346 | 0 | fn to_reducer(&self) -> Self::Reducer { |
347 | 0 | ListReducer |
348 | 0 | } |
349 | | } |
350 | | |
351 | | impl<T> Folder<T> for ListFolder<T> { |
352 | | type Result = LinkedList<T>; |
353 | | |
354 | 0 | fn consume(mut self, item: T) -> Self { |
355 | 0 | self.list.push_back(item); |
356 | 0 | self |
357 | 0 | } |
358 | | |
359 | 0 | fn consume_iter<I>(mut self, iter: I) -> Self |
360 | 0 | where |
361 | 0 | I: IntoIterator<Item = T>, |
362 | | { |
363 | 0 | self.list.extend(iter); |
364 | 0 | self |
365 | 0 | } |
366 | | |
367 | 0 | fn complete(self) -> Self::Result { |
368 | 0 | self.list |
369 | 0 | } |
370 | | |
371 | 0 | fn full(&self) -> bool { |
372 | 0 | false |
373 | 0 | } |
374 | | } |
375 | | |
376 | | impl<T> Reducer<LinkedList<T>> for ListReducer { |
377 | 0 | fn reduce(self, mut left: LinkedList<T>, mut right: LinkedList<T>) -> LinkedList<T> { |
378 | 0 | left.append(&mut right); |
379 | 0 | left |
380 | 0 | } Unexecuted instantiation: <rayon::iter::extend::ListReducer as rayon::iter::plumbing::Reducer<alloc::collections::linked_list::LinkedList<alloc::vec::Vec<alloc::vec::Vec<u8>>>>>::reduce Unexecuted instantiation: <rayon::iter::extend::ListReducer as rayon::iter::plumbing::Reducer<alloc::collections::linked_list::LinkedList<alloc::vec::Vec<rav1e::stats::EncoderStats>>>>::reduce Unexecuted instantiation: <rayon::iter::extend::ListReducer as rayon::iter::plumbing::Reducer<alloc::collections::linked_list::LinkedList<_>>>::reduce |
381 | | } |
382 | | |
383 | | /// Extends an OS-string with string slices from a parallel iterator. |
384 | | impl<'a> ParallelExtend<&'a OsStr> for OsString { |
385 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
386 | 0 | where |
387 | 0 | I: IntoParallelIterator<Item = &'a OsStr>, |
388 | | { |
389 | 0 | extend_reserved!(self, par_iter, osstring_len); |
390 | 0 | } |
391 | | } |
392 | | |
393 | | /// Extends an OS-string with strings from a parallel iterator. |
394 | | impl ParallelExtend<OsString> for OsString { |
395 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
396 | 0 | where |
397 | 0 | I: IntoParallelIterator<Item = OsString>, |
398 | | { |
399 | 0 | extend_reserved!(self, par_iter, osstring_len); |
400 | 0 | } |
401 | | } |
402 | | |
403 | | /// Extends an OS-string with string slices from a parallel iterator. |
404 | | impl<'a> ParallelExtend<Cow<'a, OsStr>> for OsString { |
405 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
406 | 0 | where |
407 | 0 | I: IntoParallelIterator<Item = Cow<'a, OsStr>>, |
408 | | { |
409 | 0 | extend_reserved!(self, par_iter, osstring_len); |
410 | 0 | } |
411 | | } |
412 | | |
413 | | /// Extends a string with characters from a parallel iterator. |
414 | | impl ParallelExtend<char> for String { |
415 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
416 | 0 | where |
417 | 0 | I: IntoParallelIterator<Item = char>, |
418 | | { |
419 | | // This is like `extend`, but `Vec<char>` is less efficient to deal |
420 | | // with than `String`, so instead collect to `LinkedList<String>`. |
421 | 0 | let list = par_iter.into_par_iter().drive_unindexed(ListStringConsumer); |
422 | 0 | self.reserve(list.iter().map(String::len).sum()); |
423 | 0 | self.extend(list); |
424 | 0 | } |
425 | | } |
426 | | |
427 | | /// Extends a string with copied characters from a parallel iterator. |
428 | | impl<'a> ParallelExtend<&'a char> for String { |
429 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
430 | 0 | where |
431 | 0 | I: IntoParallelIterator<Item = &'a char>, |
432 | | { |
433 | 0 | self.par_extend(par_iter.into_par_iter().copied()) |
434 | 0 | } |
435 | | } |
436 | | |
437 | | struct ListStringConsumer; |
438 | | |
439 | | struct ListStringFolder { |
440 | | string: String, |
441 | | } |
442 | | |
443 | | impl Consumer<char> for ListStringConsumer { |
444 | | type Folder = ListStringFolder; |
445 | | type Reducer = ListReducer; |
446 | | type Result = LinkedList<String>; |
447 | | |
448 | 0 | fn split_at(self, _index: usize) -> (Self, Self, Self::Reducer) { |
449 | 0 | (Self, Self, ListReducer) |
450 | 0 | } |
451 | | |
452 | 0 | fn into_folder(self) -> Self::Folder { |
453 | 0 | ListStringFolder { |
454 | 0 | string: String::new(), |
455 | 0 | } |
456 | 0 | } |
457 | | |
458 | 0 | fn full(&self) -> bool { |
459 | 0 | false |
460 | 0 | } |
461 | | } |
462 | | |
463 | | impl UnindexedConsumer<char> for ListStringConsumer { |
464 | 0 | fn split_off_left(&self) -> Self { |
465 | 0 | Self |
466 | 0 | } |
467 | | |
468 | 0 | fn to_reducer(&self) -> Self::Reducer { |
469 | 0 | ListReducer |
470 | 0 | } |
471 | | } |
472 | | |
473 | | impl Folder<char> for ListStringFolder { |
474 | | type Result = LinkedList<String>; |
475 | | |
476 | 0 | fn consume(mut self, item: char) -> Self { |
477 | 0 | self.string.push(item); |
478 | 0 | self |
479 | 0 | } |
480 | | |
481 | 0 | fn consume_iter<I>(mut self, iter: I) -> Self |
482 | 0 | where |
483 | 0 | I: IntoIterator<Item = char>, |
484 | | { |
485 | 0 | self.string.extend(iter); |
486 | 0 | self |
487 | 0 | } |
488 | | |
489 | 0 | fn complete(self) -> Self::Result { |
490 | 0 | let mut list = LinkedList::new(); |
491 | 0 | if !self.string.is_empty() { |
492 | 0 | list.push_back(self.string); |
493 | 0 | } |
494 | 0 | list |
495 | 0 | } |
496 | | |
497 | 0 | fn full(&self) -> bool { |
498 | 0 | false |
499 | 0 | } |
500 | | } |
501 | | |
502 | | /// Extends a string with string slices from a parallel iterator. |
503 | | impl<'a> ParallelExtend<&'a str> for String { |
504 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
505 | 0 | where |
506 | 0 | I: IntoParallelIterator<Item = &'a str>, |
507 | | { |
508 | 0 | extend_reserved!(self, par_iter, string_len); |
509 | 0 | } |
510 | | } |
511 | | |
512 | | /// Extends a string with strings from a parallel iterator. |
513 | | impl ParallelExtend<String> for String { |
514 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
515 | 0 | where |
516 | 0 | I: IntoParallelIterator<Item = String>, |
517 | | { |
518 | 0 | extend_reserved!(self, par_iter, string_len); |
519 | 0 | } |
520 | | } |
521 | | |
522 | | /// Extends a string with boxed strings from a parallel iterator. |
523 | | impl ParallelExtend<Box<str>> for String { |
524 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
525 | 0 | where |
526 | 0 | I: IntoParallelIterator<Item = Box<str>>, |
527 | | { |
528 | 0 | extend_reserved!(self, par_iter, string_len); |
529 | 0 | } |
530 | | } |
531 | | |
532 | | /// Extends a string with string slices from a parallel iterator. |
533 | | impl<'a> ParallelExtend<Cow<'a, str>> for String { |
534 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
535 | 0 | where |
536 | 0 | I: IntoParallelIterator<Item = Cow<'a, str>>, |
537 | | { |
538 | 0 | extend_reserved!(self, par_iter, string_len); |
539 | 0 | } |
540 | | } |
541 | | |
542 | | /// Extends a deque with items from a parallel iterator. |
543 | | impl<T> ParallelExtend<T> for VecDeque<T> |
544 | | where |
545 | | T: Send, |
546 | | { |
547 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
548 | 0 | where |
549 | 0 | I: IntoParallelIterator<Item = T>, |
550 | | { |
551 | 0 | extend_reserved!(self, par_iter); |
552 | 0 | } |
553 | | } |
554 | | |
555 | | /// Extends a deque with copied items from a parallel iterator. |
556 | | impl<'a, T> ParallelExtend<&'a T> for VecDeque<T> |
557 | | where |
558 | | T: 'a + Copy + Send + Sync, |
559 | | { |
560 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
561 | 0 | where |
562 | 0 | I: IntoParallelIterator<Item = &'a T>, |
563 | | { |
564 | 0 | extend_reserved!(self, par_iter); |
565 | 0 | } |
566 | | } |
567 | | |
568 | | /// Extends a vector with items from a parallel iterator. |
569 | | impl<T> ParallelExtend<T> for Vec<T> |
570 | | where |
571 | | T: Send, |
572 | | { |
573 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
574 | 0 | where |
575 | 0 | I: IntoParallelIterator<Item = T>, |
576 | | { |
577 | | // See the vec_collect benchmarks in rayon-demo for different strategies. |
578 | 0 | let par_iter = par_iter.into_par_iter(); |
579 | 0 | match par_iter.opt_len() { |
580 | 0 | Some(len) => { |
581 | 0 | // When Rust gets specialization, we can get here for indexed iterators |
582 | 0 | // without relying on `opt_len`. Until then, `special_extend()` fakes |
583 | 0 | // an unindexed mode on the promise that `opt_len()` is accurate. |
584 | 0 | super::collect::special_extend(par_iter, len, self); |
585 | 0 | } |
586 | | None => { |
587 | | // This works like `extend`, but `Vec::append` is more efficient. |
588 | 0 | let list = par_iter.drive_unindexed(ListVecConsumer); |
589 | 0 | self.reserve(list.iter().map(Vec::len).sum()); |
590 | 0 | for mut other in list { |
591 | 0 | self.append(&mut other); |
592 | 0 | } |
593 | | } |
594 | | } |
595 | 0 | } Unexecuted instantiation: <alloc::vec::Vec<alloc::vec::Vec<u8>> as rayon::iter::ParallelExtend<alloc::vec::Vec<u8>>>::par_extend::<rayon::iter::unzip::UnzipA<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u16>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u16>::{closure#0}>, rayon::iter::unzip::Unzip, alloc::vec::Vec<rav1e::stats::EncoderStats>>> Unexecuted instantiation: <alloc::vec::Vec<rav1e::stats::EncoderStats> as rayon::iter::ParallelExtend<rav1e::stats::EncoderStats>>::par_extend::<rayon::iter::unzip::UnzipB<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u16>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u16>::{closure#0}>, rayon::iter::unzip::Unzip, rayon::iter::collect::consumer::CollectConsumer<alloc::vec::Vec<u8>>>> Unexecuted instantiation: <alloc::vec::Vec<rav1e::stats::EncoderStats> as rayon::iter::ParallelExtend<rav1e::stats::EncoderStats>>::par_extend::<rayon::iter::unzip::UnzipB<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u16>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u16>::{closure#0}>, rayon::iter::unzip::Unzip, rayon::iter::extend::ListVecConsumer>> Unexecuted instantiation: <alloc::vec::Vec<alloc::vec::Vec<u8>> as rayon::iter::ParallelExtend<alloc::vec::Vec<u8>>>::par_extend::<rayon::iter::unzip::UnzipA<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u8>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u8>::{closure#0}>, rayon::iter::unzip::Unzip, alloc::vec::Vec<rav1e::stats::EncoderStats>>> Unexecuted instantiation: <alloc::vec::Vec<rav1e::stats::EncoderStats> as rayon::iter::ParallelExtend<rav1e::stats::EncoderStats>>::par_extend::<rayon::iter::unzip::UnzipB<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u8>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u8>::{closure#0}>, rayon::iter::unzip::Unzip, rayon::iter::collect::consumer::CollectConsumer<alloc::vec::Vec<u8>>>> Unexecuted instantiation: <alloc::vec::Vec<rav1e::stats::EncoderStats> as rayon::iter::ParallelExtend<rav1e::stats::EncoderStats>>::par_extend::<rayon::iter::unzip::UnzipB<rayon::iter::map::Map<rayon::vec::IntoIter<(rav1e::tiling::tiler::TileContextMut<u8>, &mut rav1e::context::cdf_context::CDFContext)>, rav1e::encoder::encode_tile_group<u8>::{closure#0}>, rayon::iter::unzip::Unzip, rayon::iter::extend::ListVecConsumer>> Unexecuted instantiation: <alloc::vec::Vec<_> as rayon::iter::ParallelExtend<_>>::par_extend::<_> |
596 | | } |
597 | | |
598 | | /// Extends a vector with copied items from a parallel iterator. |
599 | | impl<'a, T> ParallelExtend<&'a T> for Vec<T> |
600 | | where |
601 | | T: 'a + Copy + Send + Sync, |
602 | | { |
603 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
604 | 0 | where |
605 | 0 | I: IntoParallelIterator<Item = &'a T>, |
606 | | { |
607 | 0 | self.par_extend(par_iter.into_par_iter().copied()) |
608 | 0 | } |
609 | | } |
610 | | |
611 | | /// Collapses all unit items from a parallel iterator into one. |
612 | | impl ParallelExtend<()> for () { |
613 | 0 | fn par_extend<I>(&mut self, par_iter: I) |
614 | 0 | where |
615 | 0 | I: IntoParallelIterator<Item = ()>, |
616 | | { |
617 | 0 | par_iter.into_par_iter().drive_unindexed(NoopConsumer) |
618 | 0 | } |
619 | | } |