Skip to content

Commit d049ccd

Browse files
committed
Specialize count too
1 parent b2cb21b commit d049ccd

File tree

2 files changed

+44
-0
lines changed

2 files changed

+44
-0
lines changed

library/std/src/collections/hash/map.rs

+32
Original file line numberDiff line numberDiff line change
@@ -2236,6 +2236,10 @@ impl<'a, K, V> Iterator for Iter<'a, K, V> {
22362236
self.base.size_hint()
22372237
}
22382238
#[inline]
2239+
fn count(self) -> usize {
2240+
self.base.len()
2241+
}
2242+
#[inline]
22392243
fn fold<B, F>(self, init: B, f: F) -> B
22402244
where
22412245
Self: Sized,
@@ -2268,6 +2272,10 @@ impl<'a, K, V> Iterator for IterMut<'a, K, V> {
22682272
self.base.size_hint()
22692273
}
22702274
#[inline]
2275+
fn count(self) -> usize {
2276+
self.base.len()
2277+
}
2278+
#[inline]
22712279
fn fold<B, F>(self, init: B, f: F) -> B
22722280
where
22732281
Self: Sized,
@@ -2310,6 +2318,10 @@ impl<K, V> Iterator for IntoIter<K, V> {
23102318
self.base.size_hint()
23112319
}
23122320
#[inline]
2321+
fn count(self) -> usize {
2322+
self.base.len()
2323+
}
2324+
#[inline]
23132325
fn fold<B, F>(self, init: B, f: F) -> B
23142326
where
23152327
Self: Sized,
@@ -2348,6 +2360,10 @@ impl<'a, K, V> Iterator for Keys<'a, K, V> {
23482360
self.inner.size_hint()
23492361
}
23502362
#[inline]
2363+
fn count(self) -> usize {
2364+
self.inner.len()
2365+
}
2366+
#[inline]
23512367
fn fold<B, F>(self, init: B, mut f: F) -> B
23522368
where
23532369
Self: Sized,
@@ -2379,6 +2395,10 @@ impl<'a, K, V> Iterator for Values<'a, K, V> {
23792395
self.inner.size_hint()
23802396
}
23812397
#[inline]
2398+
fn count(self) -> usize {
2399+
self.inner.len()
2400+
}
2401+
#[inline]
23822402
fn fold<B, F>(self, init: B, mut f: F) -> B
23832403
where
23842404
Self: Sized,
@@ -2410,6 +2430,10 @@ impl<'a, K, V> Iterator for ValuesMut<'a, K, V> {
24102430
self.inner.size_hint()
24112431
}
24122432
#[inline]
2433+
fn count(self) -> usize {
2434+
self.inner.len()
2435+
}
2436+
#[inline]
24132437
fn fold<B, F>(self, init: B, mut f: F) -> B
24142438
where
24152439
Self: Sized,
@@ -2448,6 +2472,10 @@ impl<K, V> Iterator for IntoKeys<K, V> {
24482472
self.inner.size_hint()
24492473
}
24502474
#[inline]
2475+
fn count(self) -> usize {
2476+
self.inner.len()
2477+
}
2478+
#[inline]
24512479
fn fold<B, F>(self, init: B, mut f: F) -> B
24522480
where
24532481
Self: Sized,
@@ -2486,6 +2514,10 @@ impl<K, V> Iterator for IntoValues<K, V> {
24862514
self.inner.size_hint()
24872515
}
24882516
#[inline]
2517+
fn count(self) -> usize {
2518+
self.inner.len()
2519+
}
2520+
#[inline]
24892521
fn fold<B, F>(self, init: B, mut f: F) -> B
24902522
where
24912523
Self: Sized,

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)