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
+28 -22
View File
@@ -94,7 +94,7 @@ fn cover_or_next<I: Iterator<Item = (Range<usize>, Range<usize>)>>(
let caret_offset = caret.to_offset(map, Bias::Left);
let mut covering = vec![];
let mut next_ones = vec![];
let snapshot = &map.buffer_snapshot;
let snapshot = &map.buffer_snapshot();
if let Some(ranges) = candidates {
for (open_range, close_range) in ranges {
@@ -173,12 +173,12 @@ fn find_mini_delimiters(
is_valid_delimiter: &DelimiterPredicate,
) -> Option<Range<DisplayPoint>> {
let point = map.clip_at_line_end(display_point).to_point(map);
let offset = point.to_offset(&map.buffer_snapshot);
let offset = point.to_offset(&map.buffer_snapshot());
let line_range = get_line_range(map, point);
let visible_line_range = get_visible_line_range(&line_range);
let snapshot = &map.buffer_snapshot;
let snapshot = &map.buffer_snapshot();
let excerpt = snapshot.excerpt_containing(offset..offset)?;
let buffer = excerpt.buffer();
@@ -187,7 +187,7 @@ fn find_mini_delimiters(
};
// Try to find delimiters in visible range first
let ranges = map.buffer_snapshot.bracket_ranges(visible_line_range);
let ranges = map.buffer_snapshot().bracket_ranges(visible_line_range);
if let Some(candidate) = cover_or_next(ranges, display_point, map, Some(&bracket_filter)) {
return Some(
DelimiterRange {
@@ -740,7 +740,7 @@ fn in_word(
) -> Option<Range<DisplayPoint>> {
// Use motion::right so that we consider the character under the cursor when looking for the start
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(relative_to.to_point(map))
.ignore_punctuation(ignore_punctuation);
let start = movement::find_preceding_boundary_display_point(
@@ -765,7 +765,7 @@ fn in_subword(
let offset = relative_to.to_offset(map, Bias::Left);
// Use motion::right so that we consider the character under the cursor when looking for the start
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(relative_to.to_point(map))
.ignore_punctuation(ignore_punctuation);
let in_subword = map
@@ -838,7 +838,7 @@ pub fn surrounding_html_tag(
Some(read_tag(chars))
}
let snapshot = &map.buffer_snapshot;
let snapshot = &map.buffer_snapshot();
let offset = head.to_offset(map, Bias::Left);
let mut excerpt = snapshot.excerpt_containing(offset..offset)?;
let buffer = excerpt.buffer();
@@ -909,7 +909,7 @@ fn around_word(
) -> Option<Range<DisplayPoint>> {
let offset = relative_to.to_offset(map, Bias::Left);
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(offset)
.ignore_punctuation(ignore_punctuation);
let in_word = map
@@ -932,7 +932,7 @@ fn around_subword(
) -> Option<Range<DisplayPoint>> {
// Use motion::right so that we consider the character under the cursor when looking for the start
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(relative_to.to_point(map))
.ignore_punctuation(ignore_punctuation);
let start = movement::find_preceding_boundary_display_point(
@@ -991,7 +991,7 @@ fn around_next_word(
ignore_punctuation: bool,
) -> Option<Range<DisplayPoint>> {
let classifier = map
.buffer_snapshot
.buffer_snapshot()
.char_classifier_at(relative_to.to_point(map))
.ignore_punctuation(ignore_punctuation);
// Get the start of the word
@@ -1028,7 +1028,7 @@ fn text_object(
relative_to: DisplayPoint,
target: TextObject,
) -> Option<Range<DisplayPoint>> {
let snapshot = &map.buffer_snapshot;
let snapshot = &map.buffer_snapshot();
let offset = relative_to.to_offset(map, Bias::Left);
let mut excerpt = snapshot.excerpt_containing(offset..offset)?;
@@ -1073,7 +1073,7 @@ fn argument(
relative_to: DisplayPoint,
around: bool,
) -> Option<Range<DisplayPoint>> {
let snapshot = &map.buffer_snapshot;
let snapshot = &map.buffer_snapshot();
let offset = relative_to.to_offset(map, Bias::Left);
// The `argument` vim text object uses the syntax tree, so we operate at the buffer level and map back to the display level
@@ -1247,7 +1247,7 @@ fn indent(
// Loop forwards until we find a non-blank line with less indent
let mut end_row = row;
let max_rows = map.buffer_snapshot.max_row().0;
let max_rows = map.buffer_snapshot().max_row().0;
for next_row in (row + 1)..=max_rows {
let indent = map.line_indent_for_buffer_row(MultiBufferRow(next_row));
if indent.is_line_empty() {
@@ -1263,7 +1263,7 @@ fn indent(
end_row = next_row;
}
let end_len = map.buffer_snapshot.line_len(MultiBufferRow(end_row));
let end_len = map.buffer_snapshot().line_len(MultiBufferRow(end_row));
let start = map.point_to_display_point(Point::new(start_row, 0), Bias::Right);
let end = map.point_to_display_point(Point::new(end_row, end_len), Bias::Left);
Some(start..end)
@@ -1434,7 +1434,9 @@ fn paragraph(
let paragraph_end_row = paragraph_end.row();
let paragraph_ends_with_eof = paragraph_end_row == map.max_point().row();
let point = relative_to.to_point(map);
let current_line_is_empty = map.buffer_snapshot.is_line_blank(MultiBufferRow(point.row));
let current_line_is_empty = map
.buffer_snapshot()
.is_line_blank(MultiBufferRow(point.row));
if around {
if paragraph_ends_with_eof {
@@ -1472,10 +1474,12 @@ pub fn start_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) ->
return DisplayPoint::zero();
}
let is_current_line_blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(point.row));
let is_current_line_blank = map
.buffer_snapshot()
.is_line_blank(MultiBufferRow(point.row));
for row in (0..point.row).rev() {
let blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(row));
let blank = map.buffer_snapshot().is_line_blank(MultiBufferRow(row));
if blank != is_current_line_blank {
return Point::new(row + 1, 0).to_display_point(map);
}
@@ -1489,19 +1493,21 @@ pub fn start_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) ->
/// The trailing newline is excluded from the paragraph.
pub fn end_of_paragraph(map: &DisplaySnapshot, display_point: DisplayPoint) -> DisplayPoint {
let point = display_point.to_point(map);
if point.row == map.buffer_snapshot.max_row().0 {
if point.row == map.buffer_snapshot().max_row().0 {
return map.max_point();
}
let is_current_line_blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(point.row));
let is_current_line_blank = map
.buffer_snapshot()
.is_line_blank(MultiBufferRow(point.row));
for row in point.row + 1..map.buffer_snapshot.max_row().0 + 1 {
let blank = map.buffer_snapshot.is_line_blank(MultiBufferRow(row));
for row in point.row + 1..map.buffer_snapshot().max_row().0 + 1 {
let blank = map.buffer_snapshot().is_line_blank(MultiBufferRow(row));
if blank != is_current_line_blank {
let previous_row = row - 1;
return Point::new(
previous_row,
map.buffer_snapshot.line_len(MultiBufferRow(previous_row)),
map.buffer_snapshot().line_len(MultiBufferRow(previous_row)),
)
.to_display_point(map);
}