From 9684daa0297546a4dcf4749b1752298f7be53c1d Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Thu, 3 Sep 2020 13:24:06 +0200 Subject: Actually assert disjointness --- crates/text_edit/src/lib.rs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) (limited to 'crates/text_edit') diff --git a/crates/text_edit/src/lib.rs b/crates/text_edit/src/lib.rs index e417e8ea6..eb3c8caa2 100644 --- a/crates/text_edit/src/lib.rs +++ b/crates/text_edit/src/lib.rs @@ -119,7 +119,7 @@ impl TextEdit { return Err(other); } self.indels.extend(other.indels); - assert!(check_disjoint(&mut self.indels)); + assert_disjoint(&mut self.indels); Ok(()) } @@ -169,7 +169,7 @@ impl TextEditBuilder { } pub fn finish(self) -> TextEdit { let mut indels = self.indels; - assert!(check_disjoint(&mut indels)); + assert_disjoint(&mut indels); TextEdit { indels } } pub fn invalidates_offset(&self, offset: TextSize) -> bool { @@ -178,11 +178,14 @@ impl TextEditBuilder { fn indel(&mut self, indel: Indel) { self.indels.push(indel); if self.indels.len() <= 16 { - check_disjoint(&mut self.indels); + assert_disjoint(&mut self.indels); } } } +fn assert_disjoint(indels: &mut [impl std::borrow::Borrow]) { + assert!(check_disjoint(indels)); +} fn check_disjoint(indels: &mut [impl std::borrow::Borrow]) -> bool { indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end())); indels -- cgit v1.2.3