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
+3 -3
View File
@@ -154,7 +154,7 @@ pub fn deploy_context_menu(
return;
}
let display_map = editor.selections.display_map(cx);
let display_map = editor.display_snapshot(cx);
let source_anchor = display_map.display_point_to_anchor(point, text::Bias::Right);
let context_menu = if let Some(custom) = editor.custom_context_menu.take() {
let menu = custom(editor, point, window, cx);
@@ -169,8 +169,8 @@ pub fn deploy_context_menu(
return;
};
let display_map = editor.selections.display_map(cx);
let snapshot = editor.snapshot(window, cx);
let display_map = editor.display_snapshot(cx);
let buffer = snapshot.buffer_snapshot();
let anchor = buffer.anchor_before(point.to_point(&display_map));
if !display_ranges(&display_map, &editor.selections).any(|r| r.contains(&point)) {
@@ -185,7 +185,7 @@ pub fn deploy_context_menu(
let has_reveal_target = editor.target_file(cx).is_some();
let has_selections = editor
.selections
.all::<PointUtf16>(cx)
.all::<PointUtf16>(&display_map)
.into_iter()
.any(|s| !s.is_empty());
let has_git_repo = buffer