From 0755ce64869ca0a9f2241fe4dc4b08353ef0c575 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 5 Feb 2024 13:40:12 +0100 Subject: [PATCH] picker: Outline Editor::new That way crates that use Picker::new do not have to codegen constructor of Editor; tl;dr, 10% of LLVM shaved off of crates like vcs_menu or theme_selector in release mode. --- crates/picker/src/picker.rs | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/crates/picker/src/picker.rs b/crates/picker/src/picker.rs index 3b8788246f..3db2f135c2 100644 --- a/crates/picker/src/picker.rs +++ b/crates/picker/src/picker.rs @@ -58,13 +58,16 @@ impl FocusableView for Picker { } } +fn create_editor(placeholder: Arc, cx: &mut WindowContext<'_>) -> View { + cx.new_view(|cx| { + let mut editor = Editor::single_line(cx); + editor.set_placeholder_text(placeholder, cx); + editor + }) +} impl Picker { pub fn new(delegate: D, cx: &mut ViewContext) -> Self { - let editor = cx.new_view(|cx| { - let mut editor = Editor::single_line(cx); - editor.set_placeholder_text(delegate.placeholder_text(), cx); - editor - }); + let editor = create_editor(delegate.placeholder_text(), cx); cx.subscribe(&editor, Self::on_input_editor_event).detach(); let mut this = Self { delegate,