Remove memmove to improve terminal performance

Co-authored-by: Antonio <antonio@zed.dev>
This commit is contained in:
Thorsten Ball 2024-01-17 15:01:32 +01:00
parent 79679cb616
commit 51127460b2

View file

@ -250,8 +250,8 @@ impl TerminalElement {
//Layout current cell text //Layout current cell text
{ {
let cell_text = cell.c.to_string();
if !is_blank(&cell) { if !is_blank(&cell) {
let cell_text = cell.c.to_string();
let cell_style = let cell_style =
TerminalElement::cell_style(&cell, fg, theme, text_style, hyperlink); TerminalElement::cell_style(&cell, fg, theme, text_style, hyperlink);
@ -586,24 +586,6 @@ impl TerminalElement {
} }
} }
fn register_key_listeners(&self, cx: &mut WindowContext) {
cx.on_key_event({
let this = self.terminal.clone();
move |event: &ModifiersChangedEvent, phase, cx| {
if phase != DispatchPhase::Bubble {
return;
}
let handled =
this.update(cx, |term, _| term.try_modifiers_change(&event.modifiers));
if handled {
cx.refresh();
}
}
});
}
fn register_mouse_listeners( fn register_mouse_listeners(
&mut self, &mut self,
origin: Point<Pixels>, origin: Point<Pixels>,
@ -771,18 +753,33 @@ impl Element for TerminalElement {
self.register_mouse_listeners(origin, layout.mode, bounds, cx); self.register_mouse_listeners(origin, layout.mode, bounds, cx);
let mut interactivity = mem::take(&mut self.interactivity); self.interactivity
interactivity.paint(bounds, bounds.size, state, cx, |_, _, cx| { .paint(bounds, bounds.size, state, cx, |_, _, cx| {
cx.handle_input(&self.focus, terminal_input_handler); cx.handle_input(&self.focus, terminal_input_handler);
self.register_key_listeners(cx); cx.on_key_event({
let this = self.terminal.clone();
move |event: &ModifiersChangedEvent, phase, cx| {
if phase != DispatchPhase::Bubble {
return;
}
let handled =
this.update(cx, |term, _| term.try_modifiers_change(&event.modifiers));
if handled {
cx.refresh();
}
}
});
for rect in &layout.rects { for rect in &layout.rects {
rect.paint(origin, &layout, cx); rect.paint(origin, &layout, cx);
} }
cx.with_z_index(1, |cx| { cx.with_z_index(1, |cx| {
for (relative_highlighted_range, color) in layout.relative_highlighted_ranges.iter() for (relative_highlighted_range, color) in
layout.relative_highlighted_ranges.iter()
{ {
if let Some((start_y, highlighted_range_lines)) = if let Some((start_y, highlighted_range_lines)) =
to_highlighted_range_lines(relative_highlighted_range, &layout, origin) to_highlighted_range_lines(relative_highlighted_range, &layout, origin)