Skip to content

Commit bf2b012

Browse files
Philippe-Choletjswrenn
authored andcommitted
Better Product::size_hint
`b` size hint was computed even when not needed.
1 parent 8d07f6b commit bf2b012

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

src/adaptors/mod.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -365,15 +365,13 @@ where
365365
}
366366

367367
fn size_hint(&self) -> (usize, Option<usize>) {
368-
let has_cur = matches!(self.a_cur, Some(Some(_))) as usize;
369368
// Not ExactSizeIterator because size may be larger than usize
370-
let (b_min, b_max) = self.b.size_hint();
371-
372369
// Compute a * b_orig + b for both lower and upper bound
373-
size_hint::add(
374-
size_hint::mul(self.a.size_hint(), self.b_orig.size_hint()),
375-
(b_min * has_cur, b_max.map(move |x| x * has_cur)),
376-
)
370+
let mut sh = size_hint::mul(self.a.size_hint(), self.b_orig.size_hint());
371+
if matches!(self.a_cur, Some(Some(_))) {
372+
sh = size_hint::add(sh, self.b.size_hint());
373+
}
374+
sh
377375
}
378376

379377
fn fold<Acc, G>(self, mut accum: Acc, mut f: G) -> Acc

0 commit comments

Comments
 (0)