@@ -609,21 +609,26 @@ impl<V: Ord + Clone> Range<V> {
609
609
true
610
610
}
611
611
612
- /// Returns a simpler Range that contains the same versions
612
+ /// Returns a simpler Range that contains the same versions.
613
613
///
614
- /// For every one of the Versions provided in versions the existing range and
615
- /// the simplified range will agree on whether it is contained.
614
+ /// For every one of the Versions provided in versions the existing range and the simplified range will agree on whether it is contained.
616
615
/// The simplified version may include or exclude versions that are not in versions as the implementation wishes.
617
- /// For example:
618
- /// - If all the versions are contained in the original than the range will be simplified to `full`.
619
- /// - If none of the versions are contained in the original than the range will be simplified to `empty`.
620
616
///
621
- /// If versions are not sorted the correctness of this function is not guaranteed.
617
+ /// If none of the versions are contained in the original than the range will be returned unmodified.
618
+ /// If the range includes a single version, it will be returned unmodified.
619
+ /// If all the versions are contained in the original than the range will be simplified to `full`.
620
+ ///
621
+ /// If the given versions are not sorted the correctness of this function is not guaranteed.
622
622
pub fn simplify < ' s , I , BV > ( & self , versions : I ) -> Self
623
623
where
624
624
I : Iterator < Item = BV > + ' s ,
625
625
BV : Borrow < V > + ' s ,
626
626
{
627
+ // Do not simplify singletons
628
+ if self . as_singleton ( ) . is_some ( ) {
629
+ return self . clone ( ) ;
630
+ }
631
+
627
632
#[ cfg( debug_assertions) ]
628
633
let mut last: Option < BV > = None ;
629
634
// Return the segment index in the range for each version in the range, None otherwise
@@ -650,7 +655,13 @@ impl<V: Ord + Clone> Range<V> {
650
655
}
651
656
Some ( None )
652
657
} ) ;
653
- let kept_segments = group_adjacent_locations ( version_locations) ;
658
+ let mut kept_segments = group_adjacent_locations ( version_locations) . peekable ( ) ;
659
+
660
+ // Do not return null sets
661
+ if kept_segments. peek ( ) . is_none ( ) {
662
+ return self . clone ( ) ;
663
+ }
664
+
654
665
self . keep_segments ( kept_segments)
655
666
}
656
667
0 commit comments