Skip to content

Commit 9025f51

Browse files
committed
Add disjoint check back in TextEdit::union
1 parent 7581ba3 commit 9025f51

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

crates/text_edit/src/lib.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! `rust-analyzer` never mutates text itself and only sends diffs to clients,
44
//! so `TextEdit` is the ultimate representation of the work done by
55
//! rust-analyzer.
6-
use std::collections::HashSet;
76
87
pub use text_size::{TextRange, TextSize};
98

@@ -118,17 +117,13 @@ impl TextEdit {
118117
pub fn union(&mut self, other: TextEdit) -> Result<(), TextEdit> {
119118
// FIXME: can be done without allocating intermediate vector
120119
let mut all = self.iter().chain(other.iter()).collect::<Vec<_>>();
121-
if !check_disjoint_or_equal(&mut all) {
120+
if !check_disjoint_and_sort(&mut all) {
122121
return Err(other);
123122
}
124123

125-
// remove duplicates
126-
// FIXME: maybe make indels a HashSet instead to get rid of this?
127-
let our_indels = self.indels.clone();
128-
let our_indels = our_indels.iter().collect::<HashSet<_>>();
129-
let other_indels = other.indels.into_iter().filter(|i| !our_indels.contains(i));
130-
131-
self.indels.extend(other_indels);
124+
self.indels.extend(other.indels);
125+
check_disjoint_and_sort(&mut self.indels);
126+
self.indels.dedup();
132127
Ok(())
133128
}
134129

@@ -195,10 +190,11 @@ impl TextEditBuilder {
195190
}
196191
}
197192

198-
fn assert_disjoint_or_equal(indels: &mut [impl std::borrow::Borrow<Indel>]) {
199-
assert!(check_disjoint_or_equal(indels));
193+
fn assert_disjoint_or_equal(indels: &mut [Indel]) {
194+
assert!(check_disjoint_and_sort(indels));
200195
}
201-
fn check_disjoint_or_equal(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
196+
// FIXME: Remove the impl Bound here, it shouldn't be needed
197+
fn check_disjoint_and_sort(indels: &mut [impl std::borrow::Borrow<Indel>]) -> bool {
202198
indels.sort_by_key(|indel| (indel.borrow().delete.start(), indel.borrow().delete.end()));
203199
indels.iter().zip(indels.iter().skip(1)).all(|(l, r)| {
204200
let l = l.borrow();

0 commit comments

Comments
 (0)