@@ -174,7 +174,7 @@ mod decl {
174
174
#[ derive( Debug , PyPayload ) ]
175
175
struct PyItertoolsCount {
176
176
cur : PyRwLock < PyObjectRef > ,
177
- step : Option < PyIntRef > ,
177
+ step : PyIntRef ,
178
178
}
179
179
180
180
#[ derive( FromArgs ) ]
@@ -195,13 +195,7 @@ mod decl {
195
195
vm : & VirtualMachine ,
196
196
) -> PyResult {
197
197
let start: PyObjectRef = start. into_option ( ) . unwrap_or_else ( || vm. new_pyobj ( 0 ) ) ;
198
- let step = match step. into_option ( ) {
199
- Some ( int) => {
200
- let val: isize = int. try_to_primitive ( vm) ?;
201
- Some ( vm. new_pyref ( val. to_usize ( ) . unwrap_or ( 0 ) ) )
202
- }
203
- None => None ,
204
- } ;
198
+ let step: PyIntRef = step. into_option ( ) . unwrap_or_else ( || vm. new_pyref ( 1 ) ) ;
205
199
if !PyNumber :: check ( & start, vm) {
206
200
return Err ( vm. new_value_error ( "a number is require" . to_owned ( ) ) ) ;
207
201
}
@@ -228,8 +222,8 @@ mod decl {
228
222
#[ pymethod( magic) ]
229
223
fn repr ( & self , vm : & VirtualMachine ) -> PyResult < String > {
230
224
let mut cur = format ! ( "{}" , self . cur. read( ) . clone( ) . repr( vm) ?) ;
231
- let step = self . step . clone ( ) ;
232
- if let Some ( ref step) = step {
225
+ let step = format ! ( "{}" , self . step. clone( ) ) ;
226
+ if step != "1" {
233
227
cur. push_str ( ", " ) ;
234
228
cur. push_str ( & step. to_string ( ) ) ;
235
229
}
@@ -240,10 +234,9 @@ mod decl {
240
234
impl IterNext for PyItertoolsCount {
241
235
fn next ( zelf : & Py < Self > , vm : & VirtualMachine ) -> PyResult < PyIterReturn > {
242
236
let mut cur = zelf. cur . write ( ) ;
237
+ let step = zelf. step . clone ( ) ;
243
238
let result = cur. clone ( ) ;
244
- if let Some ( step) = & zelf. step {
245
- * cur = vm. _iadd ( & * cur, step. as_object ( ) ) ?;
246
- }
239
+ * cur = vm. _iadd ( & * cur, step. as_object ( ) ) ?;
247
240
Ok ( PyIterReturn :: Return ( result. to_pyobject ( vm) ) )
248
241
}
249
242
}
0 commit comments