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