multi_buffer: Reduce RefCell::borrow_mut calls to the bare minimum (#40522)
Release Notes: - N/A *or* Added/Fixed/Improved ...
This commit is contained in:
@@ -118,11 +118,11 @@ impl sum_tree::Summary for DiffHunkSummary {
|
||||
}
|
||||
|
||||
fn add_summary(&mut self, other: &Self, buffer: Self::Context<'_>) {
|
||||
self.buffer_range.start = self
|
||||
self.buffer_range.start = *self
|
||||
.buffer_range
|
||||
.start
|
||||
.min(&other.buffer_range.start, buffer);
|
||||
self.buffer_range.end = self.buffer_range.end.max(&other.buffer_range.end, buffer);
|
||||
self.buffer_range.end = *self.buffer_range.end.max(&other.buffer_range.end, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1068,8 +1068,8 @@ impl BufferDiff {
|
||||
self.range_to_hunk_range(secondary_changed_range, buffer, cx)
|
||||
{
|
||||
if let Some(range) = &mut changed_range {
|
||||
range.start = secondary_hunk_range.start.min(&range.start, buffer);
|
||||
range.end = secondary_hunk_range.end.max(&range.end, buffer);
|
||||
range.start = *secondary_hunk_range.start.min(&range.start, buffer);
|
||||
range.end = *secondary_hunk_range.end.max(&range.end, buffer);
|
||||
} else {
|
||||
changed_range = Some(secondary_hunk_range);
|
||||
}
|
||||
@@ -1083,8 +1083,8 @@ impl BufferDiff {
|
||||
if let Some((first, last)) = state.pending_hunks.first().zip(state.pending_hunks.last())
|
||||
{
|
||||
if let Some(range) = &mut changed_range {
|
||||
range.start = range.start.min(&first.buffer_range.start, buffer);
|
||||
range.end = range.end.max(&last.buffer_range.end, buffer);
|
||||
range.start = *range.start.min(&first.buffer_range.start, buffer);
|
||||
range.end = *range.end.max(&last.buffer_range.end, buffer);
|
||||
} else {
|
||||
changed_range = Some(first.buffer_range.start..last.buffer_range.end);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,13 @@ impl Lamport {
|
||||
|
||||
impl fmt::Debug for Lamport {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "Lamport {{{}: {}}}", self.replica_id, self.value)
|
||||
if *self == Self::MAX {
|
||||
write!(f, "Lamport {{MAX}}")
|
||||
} else if *self == Self::MIN {
|
||||
write!(f, "Lamport {{MIN}}")
|
||||
} else {
|
||||
write!(f, "Lamport {{{}: {}}}", self.replica_id, self.value)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -219,6 +225,8 @@ impl fmt::Debug for Global {
|
||||
}
|
||||
if timestamp.replica_id == LOCAL_BRANCH_REPLICA_ID {
|
||||
write!(f, "<branch>: {}", timestamp.value)?;
|
||||
} else if timestamp.replica_id == AGENT_REPLICA_ID {
|
||||
write!(f, "<agent>: {}", timestamp.value)?;
|
||||
} else {
|
||||
write!(f, "{}: {}", timestamp.replica_id, timestamp.value)?;
|
||||
}
|
||||
|
||||
@@ -6887,7 +6887,8 @@ impl Editor {
|
||||
continue;
|
||||
}
|
||||
|
||||
let range = Anchor::range_in_buffer(excerpt_id, buffer_id, start..end);
|
||||
let range =
|
||||
Anchor::range_in_buffer(excerpt_id, buffer_id, *start..*end);
|
||||
if highlight.kind == lsp::DocumentHighlightKind::WRITE {
|
||||
write_ranges.push(range);
|
||||
} else {
|
||||
|
||||
@@ -7465,7 +7465,7 @@ impl EditorElement {
|
||||
let clipped_start = range.start.max(&buffer_range.start, buffer);
|
||||
let clipped_end = range.end.min(&buffer_range.end, buffer);
|
||||
let range = buffer_snapshot
|
||||
.anchor_range_in_excerpt(excerpt_id, clipped_start..clipped_end)?;
|
||||
.anchor_range_in_excerpt(excerpt_id, *clipped_start..*clipped_end)?;
|
||||
let start = range.start.to_display_point(display_snapshot);
|
||||
let end = range.end.to_display_point(display_snapshot);
|
||||
let selection_layout = SelectionLayout {
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -797,7 +797,13 @@ async fn test_set_anchored_excerpts_for_path(cx: &mut TestAppContext) {
|
||||
let multibuffer = cx.new(|_| MultiBuffer::new(Capability::ReadWrite));
|
||||
let anchor_ranges_1 = multibuffer
|
||||
.update(cx, |multibuffer, cx| {
|
||||
multibuffer.set_anchored_excerpts_for_path(buffer_1.clone(), ranges_1, 2, cx)
|
||||
multibuffer.set_anchored_excerpts_for_path(
|
||||
PathKey::for_buffer(&buffer_1, cx),
|
||||
buffer_1.clone(),
|
||||
ranges_1,
|
||||
2,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await;
|
||||
let snapshot_1 = multibuffer.update(cx, |multibuffer, cx| multibuffer.snapshot(cx));
|
||||
@@ -814,7 +820,13 @@ async fn test_set_anchored_excerpts_for_path(cx: &mut TestAppContext) {
|
||||
);
|
||||
let anchor_ranges_2 = multibuffer
|
||||
.update(cx, |multibuffer, cx| {
|
||||
multibuffer.set_anchored_excerpts_for_path(buffer_2.clone(), ranges_2, 2, cx)
|
||||
multibuffer.set_anchored_excerpts_for_path(
|
||||
PathKey::for_buffer(&buffer_2, cx),
|
||||
buffer_2.clone(),
|
||||
ranges_2,
|
||||
2,
|
||||
cx,
|
||||
)
|
||||
})
|
||||
.await;
|
||||
let snapshot_2 = multibuffer.update(cx, |multibuffer, cx| multibuffer.snapshot(cx));
|
||||
|
||||
@@ -72,13 +72,15 @@ impl ConflictSetSnapshot {
|
||||
(None, None) => None,
|
||||
(None, Some(conflict)) => Some(conflict.range.start),
|
||||
(Some(conflict), None) => Some(conflict.range.start),
|
||||
(Some(first), Some(second)) => Some(first.range.start.min(&second.range.start, buffer)),
|
||||
(Some(first), Some(second)) => {
|
||||
Some(*first.range.start.min(&second.range.start, buffer))
|
||||
}
|
||||
};
|
||||
let end = match (old_conflicts.last(), new_conflicts.last()) {
|
||||
(None, None) => None,
|
||||
(None, Some(conflict)) => Some(conflict.range.end),
|
||||
(Some(first), None) => Some(first.range.end),
|
||||
(Some(first), Some(second)) => Some(first.range.end.max(&second.range.end, buffer)),
|
||||
(Some(first), Some(second)) => Some(*first.range.end.max(&second.range.end, buffer)),
|
||||
};
|
||||
ConflictSetUpdate {
|
||||
buffer_range: start.zip(end).map(|(start, end)| start..end),
|
||||
|
||||
@@ -8,7 +8,8 @@ use crate::{
|
||||
use anyhow::Context as _;
|
||||
use collections::HashMap;
|
||||
use editor::{
|
||||
Anchor, Editor, EditorEvent, EditorSettings, MAX_TAB_TITLE_LEN, MultiBuffer, SelectionEffects,
|
||||
Anchor, Editor, EditorEvent, EditorSettings, MAX_TAB_TITLE_LEN, MultiBuffer, PathKey,
|
||||
SelectionEffects,
|
||||
actions::{Backtab, SelectAll, Tab},
|
||||
items::active_match_index,
|
||||
multibuffer_context_lines,
|
||||
@@ -340,6 +341,7 @@ impl ProjectSearch {
|
||||
.into_iter()
|
||||
.map(|(buffer, ranges)| {
|
||||
excerpts.set_anchored_excerpts_for_path(
|
||||
PathKey::for_buffer(&buffer, cx),
|
||||
buffer,
|
||||
ranges,
|
||||
multibuffer_context_lines(cx),
|
||||
|
||||
@@ -45,19 +45,19 @@ impl Anchor {
|
||||
.then_with(|| self.bias.cmp(&other.bias))
|
||||
}
|
||||
|
||||
pub fn min(&self, other: &Self, buffer: &BufferSnapshot) -> Self {
|
||||
pub fn min<'a>(&'a self, other: &'a Self, buffer: &BufferSnapshot) -> &'a Self {
|
||||
if self.cmp(other, buffer).is_le() {
|
||||
*self
|
||||
self
|
||||
} else {
|
||||
*other
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
pub fn max(&self, other: &Self, buffer: &BufferSnapshot) -> Self {
|
||||
pub fn max<'a>(&'a self, other: &'a Self, buffer: &BufferSnapshot) -> &'a Self {
|
||||
if self.cmp(other, buffer).is_ge() {
|
||||
*self
|
||||
self
|
||||
} else {
|
||||
*other
|
||||
other
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user