branchless .filter(_).count()
This commit is contained in:
parent
2d0baa71b9
commit
6c940893e5
1 changed files with 10 additions and 0 deletions
|
|
@ -1099,6 +1099,16 @@ impl<I: Iterator, P> Iterator for Filter<I, P> where P: FnMut(&I::Item) -> bool
|
|||
let (_, upper) = self.iter.size_hint();
|
||||
(0, upper) // can't know a lower bound, due to the predicate
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn count(self) -> usize {
|
||||
let (mut c, mut predicate, mut iter) = (0, self.predicate, self.iter);
|
||||
for x in iter.by_ref() {
|
||||
// branchless count
|
||||
c += (&mut predicate)(&x) as usize;
|
||||
}
|
||||
c
|
||||
}
|
||||
}
|
||||
|
||||
#[stable(feature = "rust1", since = "1.0.0")]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue