Skip to content

Commit

Permalink
perf: Specialize Iterator::count when for Drain, IntoIter and `…
Browse files Browse the repository at this point in the history
…Iter`
  • Loading branch information
GrayJack committed Nov 26, 2024
1 parent 7cb6d48 commit e6e8b6c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1073,6 +1073,11 @@ impl<T: PrimInt, const N: usize> Iterator for Drain<'_, T, N> {
let len = self.inner.len();
(len, Some(len))
}

fn count(self) -> usize
where Self: Sized {
self.len()
}
}

impl<T: PrimInt, const N: usize> ExactSizeIterator for Drain<'_, T, N> {
Expand Down Expand Up @@ -1136,6 +1141,11 @@ impl<T: PrimInt, const N: usize> Iterator for IntoIter<T, N> {
let len = self.0.len();
(len, Some(len))
}

fn count(self) -> usize
where Self: Sized {
self.len()
}
}

impl<T: PrimInt, const N: usize> DoubleEndedIterator for IntoIter<T, N> {
Expand All @@ -1158,6 +1168,7 @@ impl<T: PrimInt, const N: usize> DoubleEndedIterator for IntoIter<T, N> {

impl<T: PrimInt, const N: usize> FusedIterator for IntoIter<T, N> {}
impl<T: PrimInt, const N: usize> ExactSizeIterator for IntoIter<T, N> {
#[inline]
fn len(&self) -> usize {
self.0.len()
}
Expand Down Expand Up @@ -1224,6 +1235,11 @@ impl<T: PrimInt, const N: usize> Iterator for Iter<'_, T, N> {
let len = self.borrow.len() - self.passed_count;
(len, Some(len))
}

fn count(self) -> usize
where Self: Sized {
self.len()
}
}

impl<T: PrimInt, const N: usize> DoubleEndedIterator for Iter<'_, T, N> {
Expand All @@ -1244,6 +1260,7 @@ impl<T: PrimInt, const N: usize> DoubleEndedIterator for Iter<'_, T, N> {

impl<T: PrimInt, const N: usize> FusedIterator for Iter<'_, T, N> {}
impl<T: PrimInt, const N: usize> ExactSizeIterator for Iter<'_, T, N> {
#[inline]
fn len(&self) -> usize {
self.borrow.len() - self.passed_count
}
Expand Down

0 comments on commit e6e8b6c

Please sign in to comment.