Skip to content

Commit d0d8d4f

Browse files
MultiProduct values: comment with code (2)
Separate `Populated/NotYetPopulated` in `match` blocks. Indents change quite a bit.
1 parent 2b0b593 commit d0d8d4f

File tree

1 file changed

+38
-32
lines changed

1 file changed

+38
-32
lines changed

src/adaptors/multi_product.rs

+38-32
Original file line numberDiff line numberDiff line change
@@ -138,45 +138,51 @@ where
138138
fn count(self) -> usize {
139139
match self.0 {
140140
ProductEnded => 0,
141-
ProductInProgress(MultiProductInner { iters, cur }) => {
142-
if cur.is_none() {
143-
// The iterator is fresh so the count is the product of the length of each iterator:
144-
// - If one of them is empty, stop counting.
145-
// - Less `count()` calls than the general case.
146-
iters
147-
.into_iter()
148-
.map(|iter| iter.iter_orig.count())
149-
.try_fold(1, |product, count| {
150-
if count == 0 {
151-
None
152-
} else {
153-
Some(product * count)
154-
}
155-
})
156-
.unwrap_or_default()
157-
} else {
158-
// The general case.
159-
iters.into_iter().fold(0, |mut acc, iter| {
160-
if acc != 0 {
161-
acc *= iter.iter_orig.count();
162-
}
163-
acc + iter.iter.count()
164-
})
141+
// The iterator is fresh so the count is the product of the length of each iterator:
142+
// - If one of them is empty, stop counting.
143+
// - Less `count()` calls than the general case.
144+
ProductInProgress(MultiProductInner {
145+
iters,
146+
cur: NotYetPopulated,
147+
}) => iters
148+
.into_iter()
149+
.map(|iter| iter.iter_orig.count())
150+
.try_fold(1, |product, count| {
151+
if count == 0 {
152+
None
153+
} else {
154+
Some(product * count)
155+
}
156+
})
157+
.unwrap_or_default(),
158+
// The general case.
159+
ProductInProgress(MultiProductInner {
160+
iters,
161+
cur: Populated(_),
162+
}) => iters.into_iter().fold(0, |mut acc, iter| {
163+
if acc != 0 {
164+
acc *= iter.iter_orig.count();
165165
}
166-
}
166+
acc + iter.iter.count()
167+
}),
167168
}
168169
}
169170

170171
fn size_hint(&self) -> (usize, Option<usize>) {
171172
match &self.0 {
172173
ProductEnded => (0, Some(0)),
173-
ProductInProgress(MultiProductInner { iters, cur }) => {
174-
if cur.is_none() {
175-
iters
176-
.iter()
177-
.map(|iter| iter.iter_orig.size_hint())
178-
.fold((1, Some(1)), size_hint::mul)
179-
} else if let [first, tail @ ..] = &iters[..] {
174+
ProductInProgress(MultiProductInner {
175+
iters,
176+
cur: NotYetPopulated,
177+
}) => iters
178+
.iter()
179+
.map(|iter| iter.iter_orig.size_hint())
180+
.fold((1, Some(1)), size_hint::mul),
181+
ProductInProgress(MultiProductInner {
182+
iters,
183+
cur: Populated(_),
184+
}) => {
185+
if let [first, tail @ ..] = &iters[..] {
180186
tail.iter().fold(first.iter.size_hint(), |mut sh, iter| {
181187
sh = size_hint::mul(sh, iter.iter_orig.size_hint());
182188
size_hint::add(sh, iter.iter.size_hint())

0 commit comments

Comments
 (0)