Skip to content

Commit

Permalink
Specialize count too
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Dec 4, 2023
1 parent 6318cbb commit 7d369f9
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
32 changes: 32 additions & 0 deletions library/std/src/collections/hash/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2233,6 +2233,10 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
self.base.size_hint()
}
#[inline]
fn count(self) -> usize {
self.base.len()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2265,6 +2269,10 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
self.base.size_hint()
}
#[inline]
fn count(self) -> usize {
self.base.len()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2307,6 +2315,10 @@ impl<K, V> Iterator for IntoIter<K, V> {
self.base.size_hint()
}
#[inline]
fn count(self) -> usize {
self.base.len()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2345,6 +2357,10 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
self.inner.size_hint()
}
#[inline]
fn count(self) -> usize {
self.inner.len()
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2376,6 +2392,10 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
self.inner.size_hint()
}
#[inline]
fn count(self) -> usize {
self.inner.len()
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2407,6 +2427,10 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
self.inner.size_hint()
}
#[inline]
fn count(self) -> usize {
self.inner.len()
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2445,6 +2469,10 @@ impl<K, V> Iterator for IntoKeys<K, V> {
self.inner.size_hint()
}
#[inline]
fn count(self) -> usize {
self.inner.len()
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -2483,6 +2511,10 @@ impl<K, V> Iterator for IntoValues<K, V> {
self.inner.size_hint()
}
#[inline]
fn count(self) -> usize {
self.inner.len()
}
#[inline]
fn fold<B, F>(self, init: B, mut f: F) -> B
where
Self: Sized,
Expand Down
12 changes: 12 additions & 0 deletions library/std/src/collections/hash/set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1501,6 +1501,10 @@ impl<'a, K> Iterator for Iter<'a, K> {
self.base.size_hint()
}
#[inline]
fn count(self) -> usize {
self.base.len()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -1539,6 +1543,10 @@ impl<K> Iterator for IntoIter<K> {
self.base.size_hint()
}
#[inline]
fn count(self) -> usize {
self.base.len()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down Expand Up @@ -1851,6 +1859,10 @@ where
self.iter.size_hint()
}
#[inline]
fn count(self) -> usize {
self.iter.count()
}
#[inline]
fn fold<B, F>(self, init: B, f: F) -> B
where
Self: Sized,
Expand Down

0 comments on commit 7d369f9

Please sign in to comment.