-
Notifications
You must be signed in to change notification settings - Fork 495
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add ParallelIterator::collect_vec_list #1128
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
use std::collections::LinkedList; | ||
|
||
use super::{IndexedParallelIterator, ParallelIterator}; | ||
|
||
mod consumer; | ||
|
@@ -64,6 +66,24 @@ where | |
}); | ||
} | ||
|
||
/// Collects the iterator into a linked list of vectors. | ||
/// | ||
/// This is called by `ParallelIterator::collect_vec_list`. | ||
pub(super) fn collect_vec_list<I>(pi: I) -> LinkedList<Vec<I::Item>> | ||
where | ||
I: ParallelIterator, | ||
{ | ||
match pi.opt_len() { | ||
Some(len) => { | ||
// Pseudo-specialization. See impl of ParallelExtend for Vec for more details. | ||
let mut v = Vec::new(); | ||
super::collect::special_extend(pi, len, &mut v); | ||
LinkedList::from([v]) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Wasn't sure if I should re-use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The way you've done it is fine, especially since that internal method is already shared The other thing I noticed is that the unindexed case avoids pushing empty vecs to the list, but here it will always create that one node. I'm not sure that matters though -- it's potentially more meaningful when there could end up being many empty list nodes, instead of just this one in a degenerate case. |
||
} | ||
None => super::extend::drive_list_vec(pi), | ||
} | ||
} | ||
|
||
/// Create a consumer on the slice of memory we are collecting into. | ||
/// | ||
/// The consumer needs to be used inside the scope function, and the | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This suggested change is fine, but I think it won't really matter since
special_extend
->collect_with_consumer
will callreserve
anyway. Allocate now or later, but we're still only doing it once.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, that was my thinking, and the ParallelExtend impl doesn't reserve here either.