Fix insert and remove behavior for empty ranges

`RangeSet::insert` and `RangeSet::remove` returned `true` when
trying to insert an empty range.
This commit is contained in:
Matthias Einwag
2021-04-03 11:26:10 -07:00
committed by Dirkjan Ochtman
parent 01b95116e9
commit e6f28e9d29
+5 -1
View File
@@ -56,7 +56,7 @@ impl RangeSet {
}
pub fn insert(&mut self, mut x: Range<u64>) -> bool {
if x.end == 0 || x.start == x.end {
if x.is_empty() {
return false;
}
if let Some((start, end)) = self.pred(x.start) {
@@ -99,6 +99,10 @@ impl RangeSet {
}
pub fn remove(&mut self, x: Range<u64>) -> bool {
if x.is_empty() {
return false;
}
let before = match self.pred(x.start) {
Some((start, end)) if end > x.start => {
self.0.remove(&start);