Skip to content

Commit

Permalink
Specialize count too
Browse files Browse the repository at this point in the history
  • Loading branch information
a1phyr committed Nov 27, 2023
1 parent b2cb21b commit d049ccd
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 @@ -2236,6 +2236,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 @@ -2268,6 +2272,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 @@ -2310,6 +2318,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 @@ -2348,6 +2360,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 @@ -2379,6 +2395,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 @@ -2410,6 +2430,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 @@ -2448,6 +2472,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 @@ -2486,6 +2514,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 d049ccd

Please sign in to comment.