Skip to content

Commit 7d369f9

Browse files
committed
Specialize count too
1 parent 6318cbb commit 7d369f9

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

Diff for: library/std/src/collections/hash/map.rs

+32
Original file line numberDiff line numberDiff line change
@@ -2233,6 +2233,10 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
22332233
self.base.size_hint()
22342234
}
22352235
#[inline]
2236+
fn count(self) -> usize {
2237+
self.base.len()
2238+
}
2239+
#[inline]
22362240
fn fold<B, F>(self, init: B, f: F) -> B
22372241
where
22382242
Self: Sized,
@@ -2265,6 +2269,10 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
22652269
self.base.size_hint()
22662270
}
22672271
#[inline]
2272+
fn count(self) -> usize {
2273+
self.base.len()
2274+
}
2275+
#[inline]
22682276
fn fold<B, F>(self, init: B, f: F) -> B
22692277
where
22702278
Self: Sized,
@@ -2307,6 +2315,10 @@ impl<K, V> Iterator for IntoIter<K, V> {
23072315
self.base.size_hint()
23082316
}
23092317
#[inline]
2318+
fn count(self) -> usize {
2319+
self.base.len()
2320+
}
2321+
#[inline]
23102322
fn fold<B, F>(self, init: B, f: F) -> B
23112323
where
23122324
Self: Sized,
@@ -2345,6 +2357,10 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
23452357
self.inner.size_hint()
23462358
}
23472359
#[inline]
2360+
fn count(self) -> usize {
2361+
self.inner.len()
2362+
}
2363+
#[inline]
23482364
fn fold<B, F>(self, init: B, mut f: F) -> B
23492365
where
23502366
Self: Sized,
@@ -2376,6 +2392,10 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
23762392
self.inner.size_hint()
23772393
}
23782394
#[inline]
2395+
fn count(self) -> usize {
2396+
self.inner.len()
2397+
}
2398+
#[inline]
23792399
fn fold<B, F>(self, init: B, mut f: F) -> B
23802400
where
23812401
Self: Sized,
@@ -2407,6 +2427,10 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
24072427
self.inner.size_hint()
24082428
}
24092429
#[inline]
2430+
fn count(self) -> usize {
2431+
self.inner.len()
2432+
}
2433+
#[inline]
24102434
fn fold<B, F>(self, init: B, mut f: F) -> B
24112435
where
24122436
Self: Sized,
@@ -2445,6 +2469,10 @@ impl<K, V> Iterator for IntoKeys<K, V> {
24452469
self.inner.size_hint()
24462470
}
24472471
#[inline]
2472+
fn count(self) -> usize {
2473+
self.inner.len()
2474+
}
2475+
#[inline]
24482476
fn fold<B, F>(self, init: B, mut f: F) -> B
24492477
where
24502478
Self: Sized,
@@ -2483,6 +2511,10 @@ impl<K, V> Iterator for IntoValues<K, V> {
24832511
self.inner.size_hint()
24842512
}
24852513
#[inline]
2514+
fn count(self) -> usize {
2515+
self.inner.len()
2516+
}
2517+
#[inline]
24862518
fn fold<B, F>(self, init: B, mut f: F) -> B
24872519
where
24882520
Self: Sized,

Diff for: library/std/src/collections/hash/set.rs

+12
Original file line numberDiff line numberDiff line change
@@ -1501,6 +1501,10 @@ impl<'a, K> Iterator for Iter<'a, K> {
15011501
self.base.size_hint()
15021502
}
15031503
#[inline]
1504+
fn count(self) -> usize {
1505+
self.base.len()
1506+
}
1507+
#[inline]
15041508
fn fold<B, F>(self, init: B, f: F) -> B
15051509
where
15061510
Self: Sized,
@@ -1539,6 +1543,10 @@ impl<K> Iterator for IntoIter<K> {
15391543
self.base.size_hint()
15401544
}
15411545
#[inline]
1546+
fn count(self) -> usize {
1547+
self.base.len()
1548+
}
1549+
#[inline]
15421550
fn fold<B, F>(self, init: B, f: F) -> B
15431551
where
15441552
Self: Sized,
@@ -1851,6 +1859,10 @@ where
18511859
self.iter.size_hint()
18521860
}
18531861
#[inline]
1862+
fn count(self) -> usize {
1863+
self.iter.count()
1864+
}
1865+
#[inline]
18541866
fn fold<B, F>(self, init: B, f: F) -> B
18551867
where
18561868
Self: Sized,

0 commit comments

Comments
 (0)