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
+2 -2
View File
@@ -69,7 +69,7 @@ impl Vim {
let mut start_offset =
selection.start.to_offset(map, Bias::Left);
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(selection.start.to_point(map));
for (ch, offset) in map.buffer_chars_at(start_offset) {
if ch == '\n' || !classifier.is_whitespace(ch) {
@@ -153,7 +153,7 @@ fn expand_changed_word_selection(
) -> Option<MotionKind> {
let is_in_word = || {
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(selection.start.to_point(map));
map.buffer_chars_at(selection.head().to_offset(map, Bias::Left))
+5 -4
View File
@@ -50,12 +50,13 @@ impl Vim {
if kind == Some(MotionKind::Linewise) {
let start = selection.start.to_point(map);
let end = selection.end.to_point(map);
if end.row < map.buffer_snapshot.max_point().row {
if end.row < map.buffer_snapshot().max_point().row {
selection.end = Point::new(end.row + 1, 0).to_display_point(map)
} else if start.row > 0 {
selection.start = Point::new(
start.row - 1,
map.buffer_snapshot.line_len(MultiBufferRow(start.row - 1)),
map.buffer_snapshot()
.line_len(MultiBufferRow(start.row - 1)),
)
.to_display_point(map)
}
@@ -183,7 +184,7 @@ impl Vim {
let mut cursor_point = cursor.to_point(map);
cursor_point.column = *column;
cursor = map
.buffer_snapshot
.buffer_snapshot()
.clip_point(cursor_point, Bias::Left)
.to_display_point(map);
}
@@ -203,7 +204,7 @@ fn move_selection_end_to_next_line(map: &DisplaySnapshot, selection: &mut Select
}
fn ends_at_eof(map: &DisplaySnapshot, selection: &mut Selection<DisplayPoint>) -> bool {
selection.end.to_point(map) == map.buffer_snapshot.max_point()
selection.end.to_point(map) == map.buffer_snapshot().max_point()
}
#[cfg(test)]
+5 -5
View File
@@ -54,11 +54,11 @@ impl Vim {
for selection in selections {
let end = movement::saturating_left(&map, selection.end);
ends.push(
map.buffer_snapshot
map.buffer_snapshot()
.anchor_before(end.to_offset(&map, Bias::Left)),
);
starts.push(
map.buffer_snapshot
map.buffer_snapshot()
.anchor_before(selection.start.to_offset(&map, Bias::Left)),
);
reversed.push(selection.reversed)
@@ -106,7 +106,7 @@ impl Vim {
point = motion::first_non_whitespace(&map.display_snapshot, false, point);
anchor = map
.display_snapshot
.buffer_snapshot
.buffer_snapshot()
.anchor_before(point.to_point(&map.display_snapshot));
}
@@ -239,7 +239,7 @@ impl Vim {
point = motion::first_non_whitespace(&map.display_snapshot, false, point);
anchor = map
.display_snapshot
.buffer_snapshot
.buffer_snapshot()
.anchor_before(point.to_point(&map.display_snapshot));
}
@@ -312,7 +312,7 @@ impl Vim {
")" => motion::sentence_forwards(&map, selection.head(), 1),
_ => unreachable!(),
};
map.buffer_snapshot
map.buffer_snapshot()
.anchor_before(point.to_offset(&map, Bias::Left))
})
.collect::<Vec<Anchor>>();
+4 -2
View File
@@ -159,9 +159,11 @@ impl Vim {
let point_range = display_range.start.to_point(&display_map)
..display_range.end.to_point(&display_map);
let anchor = if is_multiline || vim.mode == Mode::VisualLine {
display_map.buffer_snapshot.anchor_before(point_range.start)
display_map
.buffer_snapshot()
.anchor_before(point_range.start)
} else {
display_map.buffer_snapshot.anchor_after(point_range.end)
display_map.buffer_snapshot().anchor_after(point_range.end)
};
if *preserve {
+3 -2
View File
@@ -263,7 +263,7 @@ impl Vim {
if prior_selections.iter().any(|s| {
self.update_editor(cx, |_, editor, cx| {
!s.start
.is_valid(&editor.snapshot(window, cx).buffer_snapshot)
.is_valid(&editor.snapshot(window, cx).buffer_snapshot())
})
.unwrap_or(true)
}) {
@@ -469,7 +469,8 @@ impl Vim {
};
if let Some(result) = self.update_editor(cx, |vim, editor, cx| {
let range = action.range.buffer_range(vim, editor, window, cx)?;
let snapshot = &editor.snapshot(window, cx).buffer_snapshot;
let snapshot = editor.snapshot(window, cx);
let snapshot = snapshot.buffer_snapshot();
let end_point = Point::new(range.end.0, snapshot.line_len(range.end));
let range = snapshot.anchor_before(Point::new(range.start.0, 0))
..snapshot.anchor_after(end_point);