@@ -1334,12 +1334,8 @@ impl<'a, T> Iterator for Windows<'a, T> {
1334
1334
1335
1335
#[ inline]
1336
1336
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1337
- if self . size . get ( ) > self . v . len ( ) {
1338
- ( 0 , Some ( 0 ) )
1339
- } else {
1340
- let size = self . v . len ( ) - self . size . get ( ) + 1 ;
1341
- ( size, Some ( size) )
1342
- }
1337
+ let size = self . len ( ) ;
1338
+ ( size, Some ( size) )
1343
1339
}
1344
1340
1345
1341
#[ inline]
@@ -1407,7 +1403,12 @@ impl<'a, T> DoubleEndedIterator for Windows<'a, T> {
1407
1403
}
1408
1404
1409
1405
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1410
- impl < T > ExactSizeIterator for Windows < ' _ , T > { }
1406
+ impl < T > ExactSizeIterator for Windows < ' _ , T > {
1407
+ #[ inline]
1408
+ fn len ( & self ) -> usize {
1409
+ if self . size . get ( ) > self . v . len ( ) { 0 } else { self . v . len ( ) - self . size . get ( ) + 1 }
1410
+ }
1411
+ }
1411
1412
1412
1413
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
1413
1414
unsafe impl < T > TrustedLen for Windows < ' _ , T > { }
@@ -1483,14 +1484,8 @@ impl<'a, T> Iterator for Chunks<'a, T> {
1483
1484
1484
1485
#[ inline]
1485
1486
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1486
- if self . v . is_empty ( ) {
1487
- ( 0 , Some ( 0 ) )
1488
- } else {
1489
- let n = self . v . len ( ) / self . chunk_size ;
1490
- let rem = self . v . len ( ) % self . chunk_size ;
1491
- let n = if rem > 0 { n + 1 } else { n } ;
1492
- ( n, Some ( n) )
1493
- }
1487
+ let n = self . len ( ) ;
1488
+ ( n, Some ( n) )
1494
1489
}
1495
1490
1496
1491
#[ inline]
@@ -1590,7 +1585,18 @@ impl<'a, T> DoubleEndedIterator for Chunks<'a, T> {
1590
1585
}
1591
1586
1592
1587
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1593
- impl < T > ExactSizeIterator for Chunks < ' _ , T > { }
1588
+ impl < T > ExactSizeIterator for Chunks < ' _ , T > {
1589
+ #[ inline]
1590
+ fn len ( & self ) -> usize {
1591
+ if self . v . is_empty ( ) {
1592
+ 0
1593
+ } else {
1594
+ let n = self . v . len ( ) / self . chunk_size ;
1595
+ let rem = self . v . len ( ) % self . chunk_size ;
1596
+ if rem > 0 { n + 1 } else { n }
1597
+ }
1598
+ }
1599
+ }
1594
1600
1595
1601
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
1596
1602
unsafe impl < T > TrustedLen for Chunks < ' _ , T > { }
@@ -1659,14 +1665,8 @@ impl<'a, T> Iterator for ChunksMut<'a, T> {
1659
1665
1660
1666
#[ inline]
1661
1667
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1662
- if self . v . is_empty ( ) {
1663
- ( 0 , Some ( 0 ) )
1664
- } else {
1665
- let n = self . v . len ( ) / self . chunk_size ;
1666
- let rem = self . v . len ( ) % self . chunk_size ;
1667
- let n = if rem > 0 { n + 1 } else { n } ;
1668
- ( n, Some ( n) )
1669
- }
1668
+ let n = self . len ( ) ;
1669
+ ( n, Some ( n) )
1670
1670
}
1671
1671
1672
1672
#[ inline]
@@ -1757,7 +1757,18 @@ impl<'a, T> DoubleEndedIterator for ChunksMut<'a, T> {
1757
1757
}
1758
1758
1759
1759
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
1760
- impl < T > ExactSizeIterator for ChunksMut < ' _ , T > { }
1760
+ impl < T > ExactSizeIterator for ChunksMut < ' _ , T > {
1761
+ #[ inline]
1762
+ fn len ( & self ) -> usize {
1763
+ if self . v . is_empty ( ) {
1764
+ 0
1765
+ } else {
1766
+ let n = self . v . len ( ) / self . chunk_size ;
1767
+ let rem = self . v . len ( ) % self . chunk_size ;
1768
+ if rem > 0 { n + 1 } else { n }
1769
+ }
1770
+ }
1771
+ }
1761
1772
1762
1773
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
1763
1774
unsafe impl < T > TrustedLen for ChunksMut < ' _ , T > { }
@@ -1848,7 +1859,7 @@ impl<'a, T> Iterator for ChunksExact<'a, T> {
1848
1859
1849
1860
#[ inline]
1850
1861
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
1851
- let n = self . v . len ( ) / self . chunk_size ;
1862
+ let n = self . len ( ) ;
1852
1863
( n, Some ( n) )
1853
1864
}
1854
1865
@@ -1913,6 +1924,11 @@ impl<'a, T> DoubleEndedIterator for ChunksExact<'a, T> {
1913
1924
1914
1925
#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
1915
1926
impl < T > ExactSizeIterator for ChunksExact < ' _ , T > {
1927
+ #[ inline]
1928
+ fn len ( & self ) -> usize {
1929
+ self . v . len ( ) / self . chunk_size
1930
+ }
1931
+
1916
1932
fn is_empty ( & self ) -> bool {
1917
1933
self . v . is_empty ( )
1918
1934
}
@@ -2000,7 +2016,7 @@ impl<'a, T> Iterator for ChunksExactMut<'a, T> {
2000
2016
2001
2017
#[ inline]
2002
2018
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2003
- let n = self . v . len ( ) / self . chunk_size ;
2019
+ let n = self . len ( ) ;
2004
2020
( n, Some ( n) )
2005
2021
}
2006
2022
@@ -2069,6 +2085,11 @@ impl<'a, T> DoubleEndedIterator for ChunksExactMut<'a, T> {
2069
2085
2070
2086
#[ stable( feature = "chunks_exact" , since = "1.31.0" ) ]
2071
2087
impl < T > ExactSizeIterator for ChunksExactMut < ' _ , T > {
2088
+ #[ inline]
2089
+ fn len ( & self ) -> usize {
2090
+ self . v . len ( ) / self . chunk_size
2091
+ }
2092
+
2072
2093
fn is_empty ( & self ) -> bool {
2073
2094
self . v . is_empty ( )
2074
2095
}
@@ -2203,8 +2224,9 @@ impl<'a, T, const N: usize> DoubleEndedIterator for ArrayWindows<'a, T, N> {
2203
2224
2204
2225
#[ unstable( feature = "array_windows" , issue = "75027" ) ]
2205
2226
impl < T , const N : usize > ExactSizeIterator for ArrayWindows < ' _ , T , N > {
2206
- fn is_empty ( & self ) -> bool {
2207
- self . num == 0
2227
+ #[ inline]
2228
+ fn len ( & self ) -> usize {
2229
+ self . num
2208
2230
}
2209
2231
}
2210
2232
@@ -2313,6 +2335,13 @@ impl<'a, T, const N: usize> DoubleEndedIterator for ArrayChunks<'a, T, N> {
2313
2335
2314
2336
#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2315
2337
impl < T , const N : usize > ExactSizeIterator for ArrayChunks < ' _ , T , N > {
2338
+ #[ inline]
2339
+ fn len ( & self ) -> usize {
2340
+ let n = self . iter . len ( ) ;
2341
+ debug_assert_eq ! ( self . size_hint( ) , ( n, Some ( n) ) ) ;
2342
+ n
2343
+ }
2344
+
2316
2345
fn is_empty ( & self ) -> bool {
2317
2346
self . iter . is_empty ( )
2318
2347
}
@@ -2431,6 +2460,13 @@ impl<'a, T, const N: usize> DoubleEndedIterator for ArrayChunksMut<'a, T, N> {
2431
2460
2432
2461
#[ unstable( feature = "array_chunks" , issue = "74985" ) ]
2433
2462
impl < T , const N : usize > ExactSizeIterator for ArrayChunksMut < ' _ , T , N > {
2463
+ #[ inline]
2464
+ fn len ( & self ) -> usize {
2465
+ let n = self . iter . len ( ) ;
2466
+ debug_assert_eq ! ( self . size_hint( ) , ( n, Some ( n) ) ) ;
2467
+ n
2468
+ }
2469
+
2434
2470
fn is_empty ( & self ) -> bool {
2435
2471
self . iter . is_empty ( )
2436
2472
}
@@ -2516,14 +2552,8 @@ impl<'a, T> Iterator for RChunks<'a, T> {
2516
2552
2517
2553
#[ inline]
2518
2554
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2519
- if self . v . is_empty ( ) {
2520
- ( 0 , Some ( 0 ) )
2521
- } else {
2522
- let n = self . v . len ( ) / self . chunk_size ;
2523
- let rem = self . v . len ( ) % self . chunk_size ;
2524
- let n = if rem > 0 { n + 1 } else { n } ;
2525
- ( n, Some ( n) )
2526
- }
2555
+ let n = self . len ( ) ;
2556
+ ( n, Some ( n) )
2527
2557
}
2528
2558
2529
2559
#[ inline]
@@ -2607,7 +2637,18 @@ impl<'a, T> DoubleEndedIterator for RChunks<'a, T> {
2607
2637
}
2608
2638
2609
2639
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2610
- impl < T > ExactSizeIterator for RChunks < ' _ , T > { }
2640
+ impl < T > ExactSizeIterator for RChunks < ' _ , T > {
2641
+ #[ inline]
2642
+ fn len ( & self ) -> usize {
2643
+ if self . v . is_empty ( ) {
2644
+ 0
2645
+ } else {
2646
+ let n = self . v . len ( ) / self . chunk_size ;
2647
+ let rem = self . v . len ( ) % self . chunk_size ;
2648
+ if rem > 0 { n + 1 } else { n }
2649
+ }
2650
+ }
2651
+ }
2611
2652
2612
2653
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
2613
2654
unsafe impl < T > TrustedLen for RChunks < ' _ , T > { }
@@ -2682,14 +2723,8 @@ impl<'a, T> Iterator for RChunksMut<'a, T> {
2682
2723
2683
2724
#[ inline]
2684
2725
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2685
- if self . v . is_empty ( ) {
2686
- ( 0 , Some ( 0 ) )
2687
- } else {
2688
- let n = self . v . len ( ) / self . chunk_size ;
2689
- let rem = self . v . len ( ) % self . chunk_size ;
2690
- let n = if rem > 0 { n + 1 } else { n } ;
2691
- ( n, Some ( n) )
2692
- }
2726
+ let n = self . len ( ) ;
2727
+ ( n, Some ( n) )
2693
2728
}
2694
2729
2695
2730
#[ inline]
@@ -2778,7 +2813,18 @@ impl<'a, T> DoubleEndedIterator for RChunksMut<'a, T> {
2778
2813
}
2779
2814
2780
2815
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2781
- impl < T > ExactSizeIterator for RChunksMut < ' _ , T > { }
2816
+ impl < T > ExactSizeIterator for RChunksMut < ' _ , T > {
2817
+ #[ inline]
2818
+ fn len ( & self ) -> usize {
2819
+ if self . v . is_empty ( ) {
2820
+ 0
2821
+ } else {
2822
+ let n = self . v . len ( ) / self . chunk_size ;
2823
+ let rem = self . v . len ( ) % self . chunk_size ;
2824
+ if rem > 0 { n + 1 } else { n }
2825
+ }
2826
+ }
2827
+ }
2782
2828
2783
2829
#[ unstable( feature = "trusted_len" , issue = "37572" ) ]
2784
2830
unsafe impl < T > TrustedLen for RChunksMut < ' _ , T > { }
@@ -2868,7 +2914,7 @@ impl<'a, T> Iterator for RChunksExact<'a, T> {
2868
2914
2869
2915
#[ inline]
2870
2916
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2871
- let n = self . v . len ( ) / self . chunk_size ;
2917
+ let n = self . len ( ) ;
2872
2918
( n, Some ( n) )
2873
2919
}
2874
2920
@@ -2938,6 +2984,11 @@ impl<'a, T> DoubleEndedIterator for RChunksExact<'a, T> {
2938
2984
2939
2985
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
2940
2986
impl < ' a , T > ExactSizeIterator for RChunksExact < ' a , T > {
2987
+ #[ inline]
2988
+ fn len ( & self ) -> usize {
2989
+ self . v . len ( ) / self . chunk_size
2990
+ }
2991
+
2941
2992
fn is_empty ( & self ) -> bool {
2942
2993
self . v . is_empty ( )
2943
2994
}
@@ -3025,7 +3076,7 @@ impl<'a, T> Iterator for RChunksExactMut<'a, T> {
3025
3076
3026
3077
#[ inline]
3027
3078
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
3028
- let n = self . v . len ( ) / self . chunk_size ;
3079
+ let n = self . len ( ) ;
3029
3080
( n, Some ( n) )
3030
3081
}
3031
3082
@@ -3098,6 +3149,11 @@ impl<'a, T> DoubleEndedIterator for RChunksExactMut<'a, T> {
3098
3149
3099
3150
#[ stable( feature = "rchunks" , since = "1.31.0" ) ]
3100
3151
impl < T > ExactSizeIterator for RChunksExactMut < ' _ , T > {
3152
+ #[ inline]
3153
+ fn len ( & self ) -> usize {
3154
+ self . v . len ( ) / self . chunk_size
3155
+ }
3156
+
3101
3157
fn is_empty ( & self ) -> bool {
3102
3158
self . v . is_empty ( )
3103
3159
}
0 commit comments