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:
@@ -85,7 +85,11 @@ pub fn run(
|
||||
|
||||
let editor = editor.upgrade().context("editor was dropped")?;
|
||||
let selected_range = editor
|
||||
.update(cx, |editor, cx| editor.selections.newest_adjusted(cx))
|
||||
.update(cx, |editor, cx| {
|
||||
editor
|
||||
.selections
|
||||
.newest_adjusted(&editor.display_snapshot(cx))
|
||||
})
|
||||
.range();
|
||||
let multibuffer = editor.read(cx).buffer().clone();
|
||||
let Some(buffer) = multibuffer.read(cx).as_singleton() else {
|
||||
@@ -473,7 +477,9 @@ fn language_supported(language: &Arc<Language>, cx: &mut App) -> bool {
|
||||
fn get_language(editor: WeakEntity<Editor>, cx: &mut App) -> Option<Arc<Language>> {
|
||||
editor
|
||||
.update(cx, |editor, cx| {
|
||||
let selection = editor.selections.newest::<usize>(cx);
|
||||
let selection = editor
|
||||
.selections
|
||||
.newest::<usize>(&editor.display_snapshot(cx));
|
||||
let buffer = editor.buffer().read(cx).snapshot(cx);
|
||||
buffer.language_at(selection.head()).cloned()
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user