@@ -27,10 +27,7 @@ pub trait Step: PartialOrd + Sized {
2727 ///
2828 /// Returns `None` if it is not possible to calculate `steps_between`
2929 /// without overflow.
30- fn steps_between ( start : & Self , end : & Self , by : & Self ) -> Option < usize > ;
31-
32- /// Same as `steps_between`, but with a `by` of 1
33- fn steps_between_by_one ( start : & Self , end : & Self ) -> Option < usize > ;
30+ fn steps_between ( start : & Self , end : & Self ) -> Option < usize > ;
3431
3532 /// Replaces this step with `1`, returning itself
3633 fn replace_one ( & mut self ) -> Self ;
@@ -53,17 +50,10 @@ macro_rules! step_impl_unsigned {
5350 impl Step for $t {
5451 #[ inline]
5552 #[ allow( trivial_numeric_casts) ]
56- fn steps_between( start: & $t, end: & $t, by: & $t) -> Option <usize > {
57- if * by == 0 { return None ; }
53+ fn steps_between( start: & $t, end: & $t) -> Option <usize > {
5854 if * start < * end {
5955 // Note: We assume $t <= usize here
60- let diff = ( * end - * start) as usize ;
61- let by = * by as usize ;
62- if diff % by > 0 {
63- Some ( diff / by + 1 )
64- } else {
65- Some ( diff / by)
66- }
56+ Some ( ( * end - * start) as usize )
6757 } else {
6858 Some ( 0 )
6959 }
@@ -88,11 +78,6 @@ macro_rules! step_impl_unsigned {
8878 fn sub_one( & self ) -> Self {
8979 Sub :: sub( * self , 1 )
9080 }
91-
92- #[ inline]
93- fn steps_between_by_one( start: & Self , end: & Self ) -> Option <usize > {
94- Self :: steps_between( start, end, & 1 )
95- }
9681 }
9782 ) * )
9883}
@@ -104,30 +89,14 @@ macro_rules! step_impl_signed {
10489 impl Step for $t {
10590 #[ inline]
10691 #[ allow( trivial_numeric_casts) ]
107- fn steps_between( start: & $t, end: & $t, by: & $t) -> Option <usize > {
108- if * by == 0 { return None ; }
109- let diff: usize ;
110- let by_u: usize ;
111- if * by > 0 {
112- if * start >= * end {
113- return Some ( 0 ) ;
114- }
92+ fn steps_between( start: & $t, end: & $t) -> Option <usize > {
93+ if * start < * end {
11594 // Note: We assume $t <= isize here
11695 // Use .wrapping_sub and cast to usize to compute the
11796 // difference that may not fit inside the range of isize.
118- diff = ( * end as isize ) . wrapping_sub( * start as isize ) as usize ;
119- by_u = * by as usize ;
120- } else {
121- if * start <= * end {
122- return Some ( 0 ) ;
123- }
124- diff = ( * start as isize ) . wrapping_sub( * end as isize ) as usize ;
125- by_u = ( * by as isize ) . wrapping_mul( -1 ) as usize ;
126- }
127- if diff % by_u > 0 {
128- Some ( diff / by_u + 1 )
97+ Some ( ( * end as isize ) . wrapping_sub( * start as isize ) as usize )
12998 } else {
130- Some ( diff / by_u )
99+ Some ( 0 )
131100 }
132101 }
133102
@@ -150,11 +119,6 @@ macro_rules! step_impl_signed {
150119 fn sub_one( & self ) -> Self {
151120 Sub :: sub( * self , 1 )
152121 }
153-
154- #[ inline]
155- fn steps_between_by_one( start: & Self , end: & Self ) -> Option <usize > {
156- Self :: steps_between( start, end, & 1 )
157- }
158122 }
159123 ) * )
160124}
@@ -166,7 +130,7 @@ macro_rules! step_impl_no_between {
166130 issue = "42168" ) ]
167131 impl Step for $t {
168132 #[ inline]
169- fn steps_between( _a : & $t , _b : & $t , _by : & $t ) -> Option <usize > {
133+ fn steps_between( _start : & Self , _end : & Self ) -> Option <usize > {
170134 None
171135 }
172136
@@ -189,11 +153,6 @@ macro_rules! step_impl_no_between {
189153 fn sub_one( & self ) -> Self {
190154 Sub :: sub( * self , 1 )
191155 }
192-
193- #[ inline]
194- fn steps_between_by_one( start: & Self , end: & Self ) -> Option <usize > {
195- Self :: steps_between( start, end, & 1 )
196- }
197156 }
198157 ) * )
199158}
@@ -259,7 +218,7 @@ impl<A: Step> Iterator for ops::Range<A> {
259218
260219 #[ inline]
261220 fn size_hint ( & self ) -> ( usize , Option < usize > ) {
262- match Step :: steps_between_by_one ( & self . start , & self . end ) {
221+ match Step :: steps_between ( & self . start , & self . end ) {
263222 Some ( hint) => ( hint, Some ( hint) ) ,
264223 None => ( 0 , None )
265224 }
@@ -344,7 +303,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
344303 return ( 0 , Some ( 0 ) ) ;
345304 }
346305
347- match Step :: steps_between_by_one ( & self . start , & self . end ) {
306+ match Step :: steps_between ( & self . start , & self . end ) {
348307 Some ( hint) => ( hint. saturating_add ( 1 ) , hint. checked_add ( 1 ) ) ,
349308 None => ( 0 , None ) ,
350309 }
0 commit comments