sidebar: Improve performance of rebuild_contents (#57717)
Release Notes: - N/A or Added/Fixed/Improved ...
This commit is contained in:
1 parent
6f4aee7074
commit
3055f0a908
9 files changed
+105
-80
No files matched your search
@@ -936,7 +936,11 @@ impl ActionLog {
|
||||
let mut undo_buffers = Vec::new();
|
||||
let mut futures = Vec::new();
|
||||
|
||||
for buffer in self.changed_buffers(cx).into_keys() {
|
||||
for buffer in self
|
||||
.changed_buffers(cx)
|
||||
.map(|(buffer, _)| buffer)
|
||||
.collect::<Vec<_>>()
|
||||
{
|
||||
let buffer_ranges = vec![Anchor::min_max_range_for_buffer(
|
||||
buffer.read(cx).remote_id(),
|
||||
)];
|
||||
@@ -1023,17 +1027,19 @@ impl ActionLog {
|
||||
}
|
||||
|
||||
/// Returns the set of buffers that contain edits that haven't been reviewed by the user.
|
||||
pub fn changed_buffers(&self, cx: &App) -> BTreeMap<Entity<Buffer>, Entity<BufferDiff>> {
|
||||
pub fn changed_buffers(
|
||||
&self,
|
||||
cx: &App,
|
||||
) -> impl Iterator<Item = (Entity<Buffer>, Entity<BufferDiff>)> {
|
||||
self.tracked_buffers
|
||||
.iter()
|
||||
.filter(|(_, tracked)| tracked.has_edits(cx))
|
||||
.map(|(buffer, tracked)| (buffer.clone(), tracked.diff.clone()))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Returns the total number of lines added and removed across all unreviewed buffers.
|
||||
pub fn diff_stats(&self, cx: &App) -> DiffStats {
|
||||
DiffStats::all_files(&self.changed_buffers(cx), cx)
|
||||
DiffStats::all_files(self.changed_buffers(cx), cx)
|
||||
}
|
||||
|
||||
/// Iterate over buffers changed since last read or edited by the model
|
||||
@@ -1079,7 +1085,7 @@ impl DiffStats {
|
||||
}
|
||||
|
||||
pub fn all_files(
|
||||
changed_buffers: &BTreeMap<Entity<Buffer>, Entity<BufferDiff>>,
|
||||
changed_buffers: impl IntoIterator<Item = (Entity<Buffer>, Entity<BufferDiff>)>,
|
||||
cx: &App,
|
||||
) -> Self {
|
||||
let mut total = DiffStats::default();
|
||||
@@ -3254,21 +3260,21 @@ mod tests {
|
||||
child_log_1
|
||||
.read(cx)
|
||||
.changed_buffers(cx)
|
||||
.into_keys()
|
||||
.map(|(buffer, _)| buffer)
|
||||
.collect()
|
||||
});
|
||||
let child_2_changed: Vec<_> = cx.read(|cx| {
|
||||
child_log_2
|
||||
.read(cx)
|
||||
.changed_buffers(cx)
|
||||
.into_keys()
|
||||
.map(|(buffer, _)| buffer)
|
||||
.collect()
|
||||
});
|
||||
let parent_changed: Vec<_> = cx.read(|cx| {
|
||||
parent_log
|
||||
.read(cx)
|
||||
.changed_buffers(cx)
|
||||
.into_keys()
|
||||
.map(|(buffer, _)| buffer)
|
||||
.collect()
|
||||
});
|
||||
|
||||
@@ -3494,7 +3500,6 @@ mod tests {
|
||||
action_log
|
||||
.read(cx)
|
||||
.changed_buffers(cx)
|
||||
.into_iter()
|
||||
.map(|(buffer, diff)| {
|
||||
let snapshot = buffer.read(cx).snapshot();
|
||||
(
|
||||
|
||||
Reference in new issue
Block a user