@@ -330,18 +330,18 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
330
330
331
331
#[ inline]
332
332
fn next ( & mut self ) -> Option < A > {
333
- if self . is_empty ( ) {
334
- self . is_iterating = Some ( false ) ;
333
+ self . compute_is_empty ( ) ;
334
+ if self . is_empty . unwrap_or_default ( ) {
335
335
return None ;
336
336
}
337
- if self . start < self . end {
337
+ let is_iterating = self . start < self . end ;
338
+ self . is_empty = Some ( !is_iterating) ;
339
+ Some ( if is_iterating {
338
340
let n = self . start . add_one ( ) ;
339
- self . is_iterating = Some ( true ) ;
340
- Some ( mem:: replace ( & mut self . start , n) )
341
+ mem:: replace ( & mut self . start , n)
341
342
} else {
342
- self . is_iterating = Some ( false ) ;
343
- Some ( self . start . clone ( ) )
344
- }
343
+ self . start . clone ( )
344
+ } )
345
345
}
346
346
347
347
#[ inline]
@@ -358,8 +358,8 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
358
358
359
359
#[ inline]
360
360
fn nth ( & mut self , n : usize ) -> Option < A > {
361
- if self . is_empty ( ) {
362
- self . is_iterating = Some ( false ) ;
361
+ self . compute_is_empty ( ) ;
362
+ if self . is_empty . unwrap_or_default ( ) {
363
363
return None ;
364
364
}
365
365
@@ -368,19 +368,19 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
368
368
369
369
match plus_n. partial_cmp ( & self . end ) {
370
370
Some ( Less ) => {
371
- self . is_iterating = Some ( true ) ;
371
+ self . is_empty = Some ( false ) ;
372
372
self . start = plus_n. add_one ( ) ;
373
373
return Some ( plus_n)
374
374
}
375
375
Some ( Equal ) => {
376
- self . is_iterating = Some ( false ) ;
376
+ self . is_empty = Some ( true ) ;
377
377
return Some ( plus_n)
378
378
}
379
379
_ => { }
380
380
}
381
381
}
382
382
383
- self . is_iterating = Some ( false ) ;
383
+ self . is_empty = Some ( true ) ;
384
384
None
385
385
}
386
386
@@ -404,18 +404,18 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
404
404
impl < A : Step > DoubleEndedIterator for ops:: RangeInclusive < A > {
405
405
#[ inline]
406
406
fn next_back ( & mut self ) -> Option < A > {
407
- if self . is_empty ( ) {
408
- self . is_iterating = Some ( false ) ;
407
+ self . compute_is_empty ( ) ;
408
+ if self . is_empty . unwrap_or_default ( ) {
409
409
return None ;
410
410
}
411
- if self . start < self . end {
411
+ let is_iterating = self . start < self . end ;
412
+ self . is_empty = Some ( !is_iterating) ;
413
+ Some ( if is_iterating {
412
414
let n = self . end . sub_one ( ) ;
413
- self . is_iterating = Some ( true ) ;
414
- Some ( mem:: replace ( & mut self . end , n) )
415
+ mem:: replace ( & mut self . end , n)
415
416
} else {
416
- self . is_iterating = Some ( false ) ;
417
- Some ( self . end . clone ( ) )
418
- }
417
+ self . end . clone ( )
418
+ } )
419
419
}
420
420
}
421
421
0 commit comments