Reduce display_map snapshot creation (#39354)

Re-applies https://github.com/zed-industries/zed/pull/30840

This PR re-applies the initial
[PR](https://github.com/zed-industries/zed/pull/30840). As it was closed
because it was hard to land, because of the many conflicts. This PR
re-applies the changes for it.

In several cases we were creating multiple display_map
snapshots within the same root-level function call.
Creating a display_map snapshot is quite slow, and in some
cases we were creating the snapshot multiple times.

Release Notes:

- N/A
This commit is contained in:
Remco Smits
2025-10-17 21:56:57 +02:00
committed by GitHub
parent ef5b8c6fed
commit 7e97fcaacb
60 changed files with 853 additions and 426 deletions
+31 -10
View File
@@ -452,7 +452,10 @@ fn update_editor_selection(
window: &mut Window,
cx: &mut Context<Editor>,
) {
let newest_cursor = editor.selections.newest::<Point>(cx).head();
let newest_cursor = editor
.selections
.newest::<Point>(&editor.display_snapshot(cx))
.head();
if !diff_hunks.iter().any(|hunk| {
hunk.row_range
@@ -1895,7 +1898,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(1, 0)..Point::new(1, 0)
);
@@ -1909,7 +1914,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -1930,7 +1937,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -1962,7 +1971,9 @@ mod tests {
);
assert_eq!(
editor
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -2119,7 +2130,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(1, 0)..Point::new(1, 0)
);
@@ -2160,7 +2173,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -2181,7 +2196,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -2207,7 +2224,9 @@ mod tests {
);
assert_eq!(
editor1
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(3, 0)..Point::new(3, 0)
);
@@ -2240,7 +2259,9 @@ mod tests {
);
assert_eq!(
editor2
.update(cx, |editor, cx| editor.selections.newest::<Point>(cx))
.update(cx, |editor, cx| editor
.selections
.newest::<Point>(&editor.display_snapshot(cx)))
.range(),
Point::new(0, 0)..Point::new(0, 0)
);