Skip to content

Commit a4aef05

Browse files
committed
Remove the global short-circuit from try_fold
It will now only consider the locally-folded items for short-circuit behavior. It's expected that this will commonly be followed by a `try_reduce` or the like with its own global effect.
1 parent 8842e9d commit a4aef05

File tree

1 file changed

+5
-18
lines changed

1 file changed

+5
-18
lines changed

src/iter/try_fold.rs

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use super::plumbing::*;
22
use super::*;
33

4-
use std::sync::atomic::{AtomicBool, Ordering};
54
use std::fmt::{self, Debug};
65
use std::marker::PhantomData;
76
use super::private::Try;
@@ -53,12 +52,10 @@ impl<U, I, ID, F> ParallelIterator for TryFold<I, U, ID, F>
5352
fn drive_unindexed<C>(self, consumer: C) -> C::Result
5453
where C: UnindexedConsumer<Self::Item>
5554
{
56-
let full = AtomicBool::new(false);
5755
let consumer1 = TryFoldConsumer {
5856
base: consumer,
59-
fold_op: &self.fold_op,
6057
identity: &self.identity,
61-
full: &full,
58+
fold_op: &self.fold_op,
6259
marker: PhantomData,
6360
};
6461
self.base.drive_unindexed(consumer1)
@@ -67,9 +64,8 @@ impl<U, I, ID, F> ParallelIterator for TryFold<I, U, ID, F>
6764

6865
struct TryFoldConsumer<'c, U, C, ID: 'c, F: 'c> {
6966
base: C,
70-
fold_op: &'c F,
7167
identity: &'c ID,
72-
full: &'c AtomicBool,
68+
fold_op: &'c F,
7369
marker: PhantomData<U>,
7470
}
7571

@@ -93,12 +89,11 @@ impl<'r, U, T, C, ID, F> Consumer<T> for TryFoldConsumer<'r, U, C, ID, F>
9389
base: self.base.into_folder(),
9490
result: Ok((self.identity)()),
9591
fold_op: self.fold_op,
96-
full: self.full,
9792
}
9893
}
9994

10095
fn full(&self) -> bool {
101-
self.full.load(Ordering::Relaxed) || self.base.full()
96+
self.base.full()
10297
}
10398
}
10499

@@ -120,7 +115,6 @@ impl<'r, U, T, C, ID, F> UnindexedConsumer<T> for TryFoldConsumer<'r, U, C, ID,
120115
struct TryFoldFolder<'r, C, U: Try, F: 'r> {
121116
base: C,
122117
fold_op: &'r F,
123-
full: &'r AtomicBool,
124118
result: Result<U::Ok, U::Error>,
125119
}
126120

@@ -136,9 +130,6 @@ impl<'r, C, U, F, T> Folder<T> for TryFoldFolder<'r, C, U, F>
136130
let result = self.result.and_then(|acc| {
137131
fold_op(acc, item).into_result()
138132
});
139-
if result.is_err() {
140-
self.full.store(true, Ordering::Relaxed);
141-
}
142133
TryFoldFolder {
143134
result: result,
144135
..self
@@ -154,7 +145,7 @@ impl<'r, C, U, F, T> Folder<T> for TryFoldFolder<'r, C, U, F>
154145
}
155146

156147
fn full(&self) -> bool {
157-
self.result.is_err() || self.full.load(Ordering::Relaxed) || self.base.full()
148+
self.result.is_err() || self.base.full()
158149
}
159150
}
160151

@@ -208,12 +199,10 @@ impl<U, I, F> ParallelIterator for TryFoldWith<I, U, F>
208199
fn drive_unindexed<C>(self, consumer: C) -> C::Result
209200
where C: UnindexedConsumer<Self::Item>
210201
{
211-
let full = AtomicBool::new(false);
212202
let consumer1 = TryFoldWithConsumer {
213203
base: consumer,
214204
item: self.item,
215205
fold_op: &self.fold_op,
216-
full: &full,
217206
};
218207
self.base.drive_unindexed(consumer1)
219208
}
@@ -223,7 +212,6 @@ struct TryFoldWithConsumer<'c, C, U: Try, F: 'c> {
223212
base: C,
224213
item: U::Ok,
225214
fold_op: &'c F,
226-
full: &'c AtomicBool,
227215
}
228216

229217
impl<'r, U, T, C, F> Consumer<T> for TryFoldWithConsumer<'r, C, U, F>
@@ -247,12 +235,11 @@ impl<'r, U, T, C, F> Consumer<T> for TryFoldWithConsumer<'r, C, U, F>
247235
base: self.base.into_folder(),
248236
result: Ok(self.item),
249237
fold_op: self.fold_op,
250-
full: self.full,
251238
}
252239
}
253240

254241
fn full(&self) -> bool {
255-
self.full.load(Ordering::Relaxed) || self.base.full()
242+
self.base.full()
256243
}
257244
}
258245

0 commit comments

Comments
 (0)