From 0598a8243d291969232d45ee4a3fe1588b1ee488 Mon Sep 17 00:00:00 2001 From: Piotr Osiewicz <24362066+osiewicz@users.noreply.github.com> Date: Mon, 18 Sep 2023 11:55:44 +0200 Subject: [PATCH] chore: Hoist non-generic part out of add_action_internal. (#2981) add_action_internal shows up often in downstream crates (as it should be, since it's a generic function it's codegened in each crate that uses it); it adds non-trivial amounts of LLVM IR to the build as a whole which we can cut down a bit by doing the inner fn trick. Release Notes: - N/A --- crates/gpui/src/app.rs | 48 +++++++++++++++++++++++++++++------------- 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/crates/gpui/src/app.rs b/crates/gpui/src/app.rs index c95c0a6105..6b3cd03e8f 100644 --- a/crates/gpui/src/app.rs +++ b/crates/gpui/src/app.rs @@ -684,23 +684,41 @@ impl AppContext { ); }, ); + fn inner( + this: &mut AppContext, + name: &'static str, + deserializer: fn(serde_json::Value) -> anyhow::Result>, + action_id: TypeId, + view_id: TypeId, + handler: Box, + capture: bool, + ) { + this.action_deserializers + .entry(name) + .or_insert((action_id.clone(), deserializer)); - self.action_deserializers - .entry(A::qualified_name()) - .or_insert((TypeId::of::(), A::from_json_str)); + let actions = if capture { + &mut this.capture_actions + } else { + &mut this.actions + }; - let actions = if capture { - &mut self.capture_actions - } else { - &mut self.actions - }; - - actions - .entry(TypeId::of::()) - .or_default() - .entry(TypeId::of::()) - .or_default() - .push(handler); + actions + .entry(view_id) + .or_default() + .entry(action_id) + .or_default() + .push(handler); + } + inner( + self, + A::qualified_name(), + A::from_json_str, + TypeId::of::(), + TypeId::of::(), + handler, + capture, + ); } pub fn add_async_action(&mut self, mut handler: F)