mirror of
https://github.com/zed-industries/zed.git
synced 2025-01-01 14:15:11 +00:00
Avoid unnecessary cloning of items when calling SumTree::edit
This commit is contained in:
parent
09c4d65194
commit
457d945376
3 changed files with 7 additions and 12 deletions
|
@ -35,11 +35,7 @@ impl<T: Operation> OperationQueue<T> {
|
|||
pub fn insert(&mut self, mut ops: Vec<T>) {
|
||||
ops.sort_by_key(|op| op.timestamp());
|
||||
ops.dedup_by_key(|op| op.timestamp());
|
||||
let mut edits = ops
|
||||
.into_iter()
|
||||
.map(|op| Edit::Insert(op))
|
||||
.collect::<Vec<_>>();
|
||||
self.0.edit(&mut edits);
|
||||
self.0.edit(ops.into_iter().map(Edit::Insert).collect());
|
||||
}
|
||||
|
||||
pub fn drain(&mut self) -> Self {
|
||||
|
|
|
@ -332,7 +332,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||
};
|
||||
}
|
||||
|
||||
pub fn edit(&mut self, edits: &mut [Edit<T>]) -> Vec<T> {
|
||||
pub fn edit(&mut self, mut edits: Vec<Edit<T>>) -> Vec<T> {
|
||||
if edits.is_empty() {
|
||||
return Vec::new();
|
||||
}
|
||||
|
@ -369,7 +369,7 @@ impl<T: KeyedItem> SumTree<T> {
|
|||
|
||||
match edit {
|
||||
Edit::Insert(item) => {
|
||||
buffered_items.push(item.clone());
|
||||
buffered_items.push(item);
|
||||
}
|
||||
Edit::Remove(_) => {}
|
||||
}
|
||||
|
|
|
@ -752,14 +752,13 @@ impl BackgroundScanner {
|
|||
}
|
||||
|
||||
let mut entries = self.entries.lock();
|
||||
let prev_entries = entries.edit(&mut edits);
|
||||
let prev_entries = entries.edit(edits);
|
||||
Self::remove_stale_children(&mut *entries, prev_entries, new_parents);
|
||||
}
|
||||
|
||||
fn remove_entries(&self, inodes: impl IntoIterator<Item = u64>) {
|
||||
let mut entries = self.entries.lock();
|
||||
let prev_entries =
|
||||
entries.edit(&mut inodes.into_iter().map(Edit::Remove).collect::<Vec<_>>());
|
||||
let prev_entries = entries.edit(inodes.into_iter().map(Edit::Remove).collect());
|
||||
Self::remove_stale_children(&mut *entries, prev_entries, HashMap::new());
|
||||
}
|
||||
|
||||
|
@ -791,7 +790,7 @@ impl BackgroundScanner {
|
|||
}
|
||||
}
|
||||
|
||||
let mut parent_edits = new_parent_entries
|
||||
let parent_edits = new_parent_entries
|
||||
.into_iter()
|
||||
.map(|(_, (mut parent_entry, new_children))| {
|
||||
if let Entry::Dir { children, .. } = &mut parent_entry {
|
||||
|
@ -802,7 +801,7 @@ impl BackgroundScanner {
|
|||
Edit::Insert(parent_entry)
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
tree.edit(&mut parent_edits);
|
||||
tree.edit(parent_edits);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue