aboutsummaryrefslogtreecommitdiff
path: root/crates/text_edit/src
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2020-09-03 12:39:03 +0100
committerGitHub <[email protected]>2020-09-03 12:39:03 +0100
commit74e7422b69d35c55ff6fde77258047f0292d36e0 (patch)
treea1addbccc2002b612943f17e3ebf9ea6b7a93dce /crates/text_edit/src
parenta000346ab2c5851b65eca601996933ba611d2d32 (diff)
parent9684daa0297546a4dcf4749b1752298f7be53c1d (diff)
Merge #5942
5942: Actually assert disjointness r=matklad a=matklad bors r+ 🤖 Co-authored-by: Aleksey Kladov <[email protected]>
Diffstat (limited to 'crates/text_edit/src')
-rw-r--r--crates/text_edit/src/lib.rs9
1 files changed, 6 insertions, 3 deletions
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 {
119 return Err(other); 119 return Err(other);
120 } 120 }
121 self.indels.extend(other.indels); 121 self.indels.extend(other.indels);
122 assert!(check_disjoint(&mut self.indels)); 122 assert_disjoint(&mut self.indels);
123 Ok(()) 123 Ok(())
124 } 124 }
125 125
@@ -169,7 +169,7 @@ impl TextEditBuilder {
169 } 169 }
170 pub fn finish(self) -> TextEdit { 170 pub fn finish(self) -> TextEdit {
171 let mut indels = self.indels; 171 let mut indels = self.indels;
172 assert!(check_disjoint(&mut indels)); 172 assert_disjoint(&mut indels);
173 TextEdit { indels } 173 TextEdit { indels }
174 } 174 }
175 pub fn invalidates_offset(&self, offset: TextSize) -> bool { 175 pub fn invalidates_offset(&self, offset: TextSize) -> bool {
@@ -178,11 +178,14 @@ impl TextEditBuilder {
178 fn indel(&mut self, indel: Indel) { 178 fn indel(&mut self, indel: Indel) {
179 self.indels.push(indel); 179 self.indels.push(indel);
180 if self.indels.len() <= 16 { 180 if self.indels.len() <= 16 {
181 check_disjoint(&mut self.indels); 181 assert_disjoint(&mut self.indels);
182 } 182 }
183 } 183 }
184} 184}
185 185
186fn assert_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) {
187 assert!(check_disjoint(indels));
188}
186fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool { 189fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
187 indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end())); 190 indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end()));
188 indels 191 indels