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