mirror of
https://github.com/zed-industries/zed.git
synced 2025-02-03 17:44:30 +00:00
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:
parent
c3f6fcc682
commit
0598a8243d
1 changed files with 33 additions and 15 deletions
|
@ -684,23 +684,41 @@ impl AppContext {
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
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));
|
||||||
|
|
||||||
self.action_deserializers
|
let actions = if capture {
|
||||||
.entry(A::qualified_name())
|
&mut this.capture_actions
|
||||||
.or_insert((TypeId::of::<A>(), A::from_json_str));
|
} else {
|
||||||
|
&mut this.actions
|
||||||
|
};
|
||||||
|
|
||||||
let actions = if capture {
|
actions
|
||||||
&mut self.capture_actions
|
.entry(view_id)
|
||||||
} else {
|
.or_default()
|
||||||
&mut self.actions
|
.entry(action_id)
|
||||||
};
|
.or_default()
|
||||||
|
.push(handler);
|
||||||
actions
|
}
|
||||||
.entry(TypeId::of::<V>())
|
inner(
|
||||||
.or_default()
|
self,
|
||||||
.entry(TypeId::of::<A>())
|
A::qualified_name(),
|
||||||
.or_default()
|
A::from_json_str,
|
||||||
.push(handler);
|
TypeId::of::<A>(),
|
||||||
|
TypeId::of::<V>(),
|
||||||
|
handler,
|
||||||
|
capture,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn add_async_action<A, V, F>(&mut self, mut handler: F)
|
pub fn add_async_action<A, V, F>(&mut self, mut handler: F)
|
||||||
|
|
Loading…
Reference in a new issue