File tree Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Expand file tree Collapse file tree 1 file changed +8
-5
lines changed Original file line number Diff line number Diff line change @@ -4,7 +4,7 @@ use super::super::pyobject::{
4
4
use super :: super :: vm:: VirtualMachine ;
5
5
use super :: objint;
6
6
use super :: objtype;
7
- use num_bigint:: { BigInt , ToBigInt } ;
7
+ use num_bigint:: { BigInt , ToBigInt , Sign } ;
8
8
use num_traits:: { One , Signed , ToPrimitive , Zero } ;
9
9
10
10
#[ derive( Debug , Clone ) ]
@@ -19,10 +19,13 @@ pub struct RangeType {
19
19
impl RangeType {
20
20
#[ inline]
21
21
pub fn len ( & self ) -> usize {
22
- ( ( self . end . clone ( ) - self . start . clone ( ) ) / self . step . clone ( ) )
23
- . abs ( )
24
- . to_usize ( )
25
- . unwrap ( )
22
+ match self . step . sign ( ) {
23
+ Sign :: Plus if self . start < self . end =>
24
+ ( ( & self . end - & self . start - 1usize ) / & self . step ) . to_usize ( ) . unwrap ( ) + 1 ,
25
+ Sign :: Minus if self . start > self . end =>
26
+ ( ( & self . start - & self . end - 1usize ) / ( -& self . step ) ) . to_usize ( ) . unwrap ( ) + 1 ,
27
+ _ => 0 ,
28
+ }
26
29
}
27
30
28
31
#[ inline]
You can’t perform that action at this time.
0 commit comments