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
This commit is contained in:
Piotr Osiewicz 2023-09-18 11:55:44 +02:00 committed by GitHub
parent c3f6fcc682
commit 0598a8243d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -684,24 +684,42 @@ impl AppContext {
);
},
);
self.action_deserializers
.entry(A::qualified_name())
.or_insert((TypeId::of::<A>(), A::from_json_str));
fn inner(
this: &mut AppContext,
name: &'static str,
deserializer: fn(serde_json::Value) -> anyhow::Result<Box<dyn Action>>,
action_id: TypeId,
view_id: TypeId,
handler: Box<ActionCallback>,
capture: bool,
) {
this.action_deserializers
.entry(name)
.or_insert((action_id.clone(), deserializer));
let actions = if capture {
&mut self.capture_actions
&mut this.capture_actions
} else {
&mut self.actions
&mut this.actions
};
actions
.entry(TypeId::of::<V>())
.entry(view_id)
.or_default()
.entry(TypeId::of::<A>())
.entry(action_id)
.or_default()
.push(handler);
}
inner(
self,
A::qualified_name(),
A::from_json_str,
TypeId::of::<A>(),
TypeId::of::<V>(),
handler,
capture,
);
}
pub fn add_async_action<A, V, F>(&mut self, mut handler: F)
where