terminal: Match trait bounds with terminal input (#31441)
The core change here is the following: ```rust fn write_to_pty(&self, input: impl Into<Vec<u8>>); // into fn write_to_pty(&self, input: impl Into<Cow<'static, [u8]>>); ``` This matches the trait bounds that's used by the Alacritty crate. We are now allowed to effectively pass `&'static str` instead of always needing a `String`. The main benefit comes from making the `to_esc_str` function return a `Cow<'static, str>` instead of `String`. We save an allocation in the following instances: - When the user presses any special key that isn't alphanumerical (in the terminal) - When the uses presses any key while a modifier is active (in the terminal) - When focusing/un-focusing the terminal - When completing or undoing a terminal transaction - When starting a terminal assist This basically saves us an allocation on **every key** press in the terminal. NOTE: This same optimization can be done for **nearly all** keypresses in the entirety of Zed by changing the signature of the `Keystroke` struct in gpui. If the Zed team is interested in a PR for it, let me know. Release Notes: - N/A
This commit is contained in:
parent
56d4c0af9f
commit
8ab7d44d51
6 changed files with 162 additions and 196 deletions
|
@ -514,7 +514,7 @@ impl Project {
|
|||
terminal_handle: &Entity<Terminal>,
|
||||
cx: &mut App,
|
||||
) {
|
||||
terminal_handle.update(cx, |terminal, _| terminal.input(command));
|
||||
terminal_handle.update(cx, |terminal, _| terminal.input(command.into_bytes()));
|
||||
}
|
||||
|
||||
pub fn local_terminal_handles(&self) -> &Vec<WeakEntity<terminal::Terminal>> {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue