Actually assert disjointness

This commit is contained in:
Aleksey Kladov 2020-09-03 13:24:06 +02:00
parent a000346ab2
commit 9684daa029

View file

@ -119,7 +119,7 @@ impl TextEdit {
return Err(other); return Err(other);
} }
self.indels.extend(other.indels); self.indels.extend(other.indels);
assert!(check_disjoint(&mut self.indels)); assert_disjoint(&mut self.indels);
Ok(()) Ok(())
} }
@ -169,7 +169,7 @@ impl TextEditBuilder {
} }
pub fn finish(self) -> TextEdit { pub fn finish(self) -> TextEdit {
let mut indels = self.indels; let mut indels = self.indels;
assert!(check_disjoint(&mut indels)); assert_disjoint(&mut indels);
TextEdit { indels } TextEdit { indels }
} }
pub fn invalidates_offset(&self, offset: TextSize) -> bool { pub fn invalidates_offset(&self, offset: TextSize) -> bool {
@ -178,11 +178,14 @@ impl TextEditBuilder {
fn indel(&mut self, indel: Indel) { fn indel(&mut self, indel: Indel) {
self.indels.push(indel); self.indels.push(indel);
if self.indels.len() <= 16 { if self.indels.len() <= 16 {
check_disjoint(&mut self.indels); assert_disjoint(&mut self.indels);
} }
} }
} }
fn assert_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) {
assert!(check_disjoint(indels));
}
fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool { fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end())); indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end()));
indels indels