@@ -341,16 +341,15 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
341
341
342
342
#[ inline]
343
343
fn next ( & mut self ) -> Option < A > {
344
- self . compute_is_empty ( ) ;
345
- if self . is_empty . unwrap_or_default ( ) {
344
+ if self . is_empty ( ) {
346
345
return None ;
347
346
}
348
347
let is_iterating = self . start < self . end ;
349
- self . is_empty = Some ( !is_iterating) ;
350
348
Some ( if is_iterating {
351
349
let n = self . start . add_one ( ) ;
352
350
mem:: replace ( & mut self . start , n)
353
351
} else {
352
+ self . exhausted = true ;
354
353
self . start . clone ( )
355
354
} )
356
355
}
@@ -369,8 +368,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
369
368
370
369
#[ inline]
371
370
fn nth ( & mut self , n : usize ) -> Option < A > {
372
- self . compute_is_empty ( ) ;
373
- if self . is_empty . unwrap_or_default ( ) {
371
+ if self . is_empty ( ) {
374
372
return None ;
375
373
}
376
374
@@ -379,21 +377,20 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
379
377
380
378
match plus_n. partial_cmp ( & self . end ) {
381
379
Some ( Less ) => {
382
- self . is_empty = Some ( false ) ;
383
380
self . start = plus_n. add_one ( ) ;
384
381
return Some ( plus_n) ;
385
382
}
386
383
Some ( Equal ) => {
387
- self . is_empty = Some ( true ) ;
388
384
self . start = plus_n. clone ( ) ;
385
+ self . exhausted = true ;
389
386
return Some ( plus_n) ;
390
387
}
391
388
_ => { }
392
389
}
393
390
}
394
391
395
392
self . start = self . end . clone ( ) ;
396
- self . is_empty = Some ( true ) ;
393
+ self . exhausted = true ;
397
394
None
398
395
}
399
396
@@ -404,8 +401,6 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
404
401
F : FnMut ( B , Self :: Item ) -> R ,
405
402
R : Try < Ok = B > ,
406
403
{
407
- self . compute_is_empty ( ) ;
408
-
409
404
if self . is_empty ( ) {
410
405
return Try :: from_ok ( init) ;
411
406
}
@@ -418,7 +413,7 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
418
413
accum = f ( accum, n) ?;
419
414
}
420
415
421
- self . is_empty = Some ( true ) ;
416
+ self . exhausted = true ;
422
417
423
418
if self . start == self . end {
424
419
accum = f ( accum, self . start . clone ( ) ) ?;
@@ -447,24 +442,22 @@ impl<A: Step> Iterator for ops::RangeInclusive<A> {
447
442
impl < A : Step > DoubleEndedIterator for ops:: RangeInclusive < A > {
448
443
#[ inline]
449
444
fn next_back ( & mut self ) -> Option < A > {
450
- self . compute_is_empty ( ) ;
451
- if self . is_empty . unwrap_or_default ( ) {
445
+ if self . is_empty ( ) {
452
446
return None ;
453
447
}
454
448
let is_iterating = self . start < self . end ;
455
- self . is_empty = Some ( !is_iterating) ;
456
449
Some ( if is_iterating {
457
450
let n = self . end . sub_one ( ) ;
458
451
mem:: replace ( & mut self . end , n)
459
452
} else {
453
+ self . exhausted = true ;
460
454
self . end . clone ( )
461
455
} )
462
456
}
463
457
464
458
#[ inline]
465
459
fn nth_back ( & mut self , n : usize ) -> Option < A > {
466
- self . compute_is_empty ( ) ;
467
- if self . is_empty . unwrap_or_default ( ) {
460
+ if self . is_empty ( ) {
468
461
return None ;
469
462
}
470
463
@@ -473,21 +466,20 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
473
466
474
467
match minus_n. partial_cmp ( & self . start ) {
475
468
Some ( Greater ) => {
476
- self . is_empty = Some ( false ) ;
477
469
self . end = minus_n. sub_one ( ) ;
478
470
return Some ( minus_n) ;
479
471
}
480
472
Some ( Equal ) => {
481
- self . is_empty = Some ( true ) ;
482
473
self . end = minus_n. clone ( ) ;
474
+ self . exhausted = true ;
483
475
return Some ( minus_n) ;
484
476
}
485
477
_ => { }
486
478
}
487
479
}
488
480
489
481
self . end = self . start . clone ( ) ;
490
- self . is_empty = Some ( true ) ;
482
+ self . exhausted = true ;
491
483
None
492
484
}
493
485
@@ -498,8 +490,6 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
498
490
F : FnMut ( B , Self :: Item ) -> R ,
499
491
R : Try < Ok = B > ,
500
492
{
501
- self . compute_is_empty ( ) ;
502
-
503
493
if self . is_empty ( ) {
504
494
return Try :: from_ok ( init) ;
505
495
}
@@ -512,7 +502,7 @@ impl<A: Step> DoubleEndedIterator for ops::RangeInclusive<A> {
512
502
accum = f ( accum, n) ?;
513
503
}
514
504
515
- self . is_empty = Some ( true ) ;
505
+ self . exhausted = true ;
516
506
517
507
if self . start == self . end {
518
508
accum = f ( accum, self . start . clone ( ) ) ?;
0 commit comments