Skip to content

Commit 511f8b2

Browse files
committed
FIX: Use Zip::fold_while for final reduction in parallel array view
When fold_with is used, use Zip::fold_while to fold the array view's parallel iterator. Note that in some cases, the IntoIterator of the view is used instead.
1 parent ad856bd commit 511f8b2

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/parallel/par.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,14 @@ macro_rules! par_iter_view_wrapper {
170170
fn fold_with<F>(self, folder: F) -> F
171171
where F: Folder<Self::Item>,
172172
{
173-
self.into_iter().fold(folder, move |f, elt| f.consume(elt))
173+
Zip::from(self.0).fold_while(folder, |mut folder, elt| {
174+
folder = folder.consume(elt);
175+
if folder.full() {
176+
FoldWhile::Done(folder)
177+
} else {
178+
FoldWhile::Continue(folder)
179+
}
180+
}).into_inner()
174181
}
175182
}
176183

0 commit comments

Comments
 (0)