editor: Shrink DisplayMapSnapshot from 824 to 256 bytes (#39568)

We have unnecessary clones for the fields here as most of the snapshots
contain the others hierarchically.

Release Notes:

- N/A *or* Added/Fixed/Improved ...
This commit is contained in:
Lukas Wirth
2025-10-06 08:08:49 +00:00
committed by GitHub
parent 9c7369f54d
commit 2bfcd60b88
48 changed files with 594 additions and 543 deletions
+10 -10
View File
@@ -602,7 +602,7 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
let buffer_row = action.range.head().buffer_row(vim, editor, window, cx)?;
let current = editor.selections.newest::<Point>(cx);
let target = snapshot
.buffer_snapshot
.buffer_snapshot()
.clip_point(Point::new(buffer_row.0, current.head().column), Bias::Left);
editor.change_selections(Default::default(), window, cx, |s| {
s.select_ranges([target..target]);
@@ -624,10 +624,10 @@ pub fn register(editor: &mut Editor, cx: &mut Context<Vim>) {
vim.update_editor(cx, |vim, editor, cx| {
let snapshot = editor.snapshot(window, cx);
if let Ok(range) = action.range.buffer_range(vim, editor, window, cx) {
let end = if range.end < snapshot.buffer_snapshot.max_row() {
let end = if range.end < snapshot.buffer_snapshot().max_row() {
Point::new(range.end.0 + 1, 0)
} else {
snapshot.buffer_snapshot.max_point()
snapshot.buffer_snapshot().max_point()
};
vim.copy_ranges(
editor,
@@ -963,7 +963,7 @@ impl Position {
)
}) {
anchor
.to_point(&snapshot.buffer_snapshot)
.to_point(&snapshot.buffer_snapshot())
.row
.saturating_add_signed(*offset)
} else {
@@ -979,12 +979,12 @@ impl Position {
let Some(mark) = anchors.last() else {
anyhow::bail!("mark {name} contains empty anchors");
};
mark.to_point(&snapshot.buffer_snapshot)
mark.to_point(&snapshot.buffer_snapshot())
.row
.saturating_add_signed(*offset)
}
Position::LastLine { offset } => snapshot
.buffer_snapshot
.buffer_snapshot()
.max_row()
.0
.saturating_add_signed(*offset),
@@ -992,12 +992,12 @@ impl Position {
.selections
.newest_anchor()
.head()
.to_point(&snapshot.buffer_snapshot)
.to_point(&snapshot.buffer_snapshot())
.row
.saturating_add_signed(*offset),
};
Ok(MultiBufferRow(target).min(snapshot.buffer_snapshot.max_row()))
Ok(MultiBufferRow(target).min(snapshot.buffer_snapshot().max_row()))
}
}
@@ -1652,7 +1652,7 @@ impl OnMatchingLines {
let point_range = Point::new(range.start.0, 0)
..snapshot
.buffer_snapshot
.buffer_snapshot()
.clip_point(Point::new(range.end.0 + 1, 0), Bias::Left);
cx.spawn_in(window, async move |editor, cx| {
let new_selections = cx
@@ -1660,7 +1660,7 @@ impl OnMatchingLines {
let mut line = String::new();
let mut new_selections = Vec::new();
let chunks = snapshot
.buffer_snapshot
.buffer_snapshot()
.text_for_range(point_range)
.chain(["\n"]);