@@ -2796,93 +2796,71 @@ impl<A: Int> Iterator for RangeStepInclusive<A> {
2796
2796
}
2797
2797
}
2798
2798
2799
- macro_rules! range_impl {
2799
+ macro_rules! range_exact_iter_impl {
2800
2800
( $( $t: ty) * ) => ( $(
2801
2801
#[ stable( feature = "rust1" , since = "1.0.0" ) ]
2802
- impl Iterator for :: ops:: Range <$t> {
2803
- type Item = $t;
2804
-
2802
+ impl ExactSizeIterator for :: ops:: Range <$t> {
2805
2803
#[ inline]
2806
- fn next( & mut self ) -> Option <$t> {
2807
- if self . start < self . end {
2808
- let result = self . start;
2809
- self . start += 1 ;
2810
- return Some ( result) ;
2811
- }
2812
-
2813
- return None ;
2814
- }
2815
-
2816
- #[ inline]
2817
- fn size_hint( & self ) -> ( usize , Option <usize >) {
2804
+ fn len( & self ) -> usize {
2818
2805
debug_assert!( self . end >= self . start) ;
2819
- let hint = ( self . end - self . start) as usize ;
2820
- ( hint, Some ( hint) )
2806
+ ( self . end - self . start) as usize
2821
2807
}
2822
2808
}
2823
-
2824
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2825
- impl ExactSizeIterator for :: ops:: Range <$t> { }
2826
2809
) * )
2827
2810
}
2828
2811
2829
- macro_rules! range_impl_no_hint {
2830
- ( $( $t: ty) * ) => ( $(
2831
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2832
- impl Iterator for :: ops:: Range <$t> {
2833
- type Item = $t;
2834
-
2835
- #[ inline]
2836
- fn next( & mut self ) -> Option <$t> {
2837
- if self . start < self . end {
2838
- let result = self . start;
2839
- self . start += 1 ;
2840
- return Some ( result) ;
2841
- }
2812
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2813
+ impl < A : Int > Iterator for :: ops:: Range < A > {
2814
+ type Item = A ;
2842
2815
2843
- return None ;
2844
- }
2816
+ #[ inline]
2817
+ fn next ( & mut self ) -> Option < A > {
2818
+ if self . start < self . end {
2819
+ let result = self . start ;
2820
+ self . start = self . start + Int :: one ( ) ;
2821
+ Some ( result)
2822
+ } else {
2823
+ None
2845
2824
}
2846
- ) * )
2847
- }
2848
-
2849
- macro_rules! range_other_impls {
2850
- ( $( $t: ty) * ) => ( $(
2851
- #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2852
- impl DoubleEndedIterator for :: ops:: Range <$t> {
2853
- #[ inline]
2854
- fn next_back( & mut self ) -> Option <$t> {
2855
- if self . start < self . end {
2856
- self . end -= 1 ;
2857
- return Some ( self . end) ;
2858
- }
2825
+ }
2859
2826
2860
- return None ;
2861
- }
2862
- }
2827
+ #[ inline]
2828
+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
2829
+ debug_assert ! ( self . end >= self . start) ;
2830
+ let hint = ( self . end - self . start ) . to_uint ( ) ;
2831
+ ( hint. unwrap_or ( 0 ) , hint)
2832
+ }
2833
+ }
2863
2834
2864
- # [ stable ( feature = "rust1" , since = "1.0.0" ) ]
2865
- impl Iterator for :: ops :: RangeFrom <$t> {
2866
- type Item = $t ;
2835
+ range_exact_iter_impl ! ( usize u8 u16 u32 isize i8 i16 i32 ) ;
2836
+ # [ cfg ( target_pointer_width = "64" ) ]
2837
+ range_exact_iter_impl ! ( u64 i64 ) ;
2867
2838
2868
- #[ inline]
2869
- fn next( & mut self ) -> Option <$t> {
2870
- let result = self . start;
2871
- self . start += 1 ;
2872
- debug_assert!( result < self . start) ;
2873
- return Some ( result) ;
2874
- }
2839
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2840
+ impl < A : Int > DoubleEndedIterator for :: ops:: Range < A > {
2841
+ #[ inline]
2842
+ fn next_back ( & mut self ) -> Option < A > {
2843
+ if self . start < self . end {
2844
+ self . end = self . end - Int :: one ( ) ;
2845
+ Some ( self . end )
2846
+ } else {
2847
+ None
2875
2848
}
2876
- ) * )
2849
+ }
2877
2850
}
2878
2851
2879
- range_impl ! ( usize u8 u16 u32 isize i8 i16 i32 ) ;
2880
- #[ cfg( target_pointer_width = "64" ) ]
2881
- range_impl ! ( u64 i64 ) ;
2882
- #[ cfg( target_pointer_width = "32" ) ]
2883
- range_impl_no_hint ! ( u64 i64 ) ;
2852
+ #[ stable( feature = "rust1" , since = "1.0.0" ) ]
2853
+ impl < A : Int > Iterator for :: ops:: RangeFrom < A > {
2854
+ type Item = A ;
2884
2855
2885
- range_other_impls ! ( usize u8 u16 u32 u64 isize i8 i16 i32 i64 ) ;
2856
+ #[ inline]
2857
+ fn next ( & mut self ) -> Option < A > {
2858
+ let result = self . start ;
2859
+ self . start = self . start + Int :: one ( ) ;
2860
+ debug_assert ! ( result < self . start) ;
2861
+ Some ( result)
2862
+ }
2863
+ }
2886
2864
2887
2865
/// An iterator that repeats an element endlessly
2888
2866
#[ derive( Clone ) ]
0 commit comments