5880: Opportunistically check indel overlap r=matklad a=matklad

bors r+
🤖

Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
bors[bot] 2020-08-25 16:01:47 +00:00 committed by GitHub
commit 33c4afeae0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -159,13 +159,13 @@ impl<'a> IntoIterator for &'a TextEdit {
impl TextEditBuilder {
pub fn replace(&mut self, range: TextRange, replace_with: String) {
self.indels.push(Indel::replace(range, replace_with))
self.indel(Indel::replace(range, replace_with))
}
pub fn delete(&mut self, range: TextRange) {
self.indels.push(Indel::delete(range))
self.indel(Indel::delete(range))
}
pub fn insert(&mut self, offset: TextSize, text: String) {
self.indels.push(Indel::insert(offset, text))
self.indel(Indel::insert(offset, text))
}
pub fn finish(self) -> TextEdit {
let mut indels = self.indels;
@ -175,6 +175,12 @@ impl TextEditBuilder {
pub fn invalidates_offset(&self, offset: TextSize) -> bool {
self.indels.iter().any(|indel| indel.delete.contains_inclusive(offset))
}
fn indel(&mut self, indel: Indel) {
self.indels.push(indel);
if self.indels.len() <= 16 {
check_disjoint(&mut self.indels);
}
}
}
fn check_disjoint(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {