1
0
Fork 0
mirror of https://github.com/alacritty/alacritty.git synced 2024-11-11 13:51:01 -05:00

Fix inefficient search initialization

The creation of the renderable search iterator was doing a lot of work
even when absolutely no search is active at the moment. To resolve this
problem, an early return now makes sure that a search is active before
going through the trouble of creating an iterator for it.
This commit is contained in:
Christian Duerr 2021-01-07 05:19:37 +00:00 committed by GitHub
parent 9f560b3e11
commit fb9b362b6e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 3 deletions

View file

@ -492,12 +492,11 @@ impl Display {
self.renderer.with_api(&config.ui_config, &size_info, |mut api| { self.renderer.with_api(&config.ui_config, &size_info, |mut api| {
// Iterate over all non-empty cells in the grid. // Iterate over all non-empty cells in the grid.
for mut cell in grid_cells { for mut cell in grid_cells {
// Invert the active match in vi-less search. // Invert the active match during search.
let cell_point = Point::new(cell.line, cell.column);
if cell.is_match if cell.is_match
&& viewport_match && viewport_match
.as_ref() .as_ref()
.map_or(false, |viewport_match| viewport_match.contains(&cell_point)) .map_or(false, |viewport_match| viewport_match.contains(&cell.point()))
{ {
let colors = config.colors.search.focused_match; let colors = config.colors.search.focused_match;
let match_fg = colors.foreground.color(cell.fg, cell.bg); let match_fg = colors.foreground.color(cell.fg, cell.bg);

View file

@ -258,6 +258,11 @@ impl RenderableCell {
} }
} }
/// Position of the cell.
pub fn point(&self) -> Point {
Point::new(self.line, self.column)
}
/// Check if cell contains any renderable content. /// Check if cell contains any renderable content.
fn is_empty(&self) -> bool { fn is_empty(&self) -> bool {
self.bg_alpha == 0. self.bg_alpha == 0.
@ -370,6 +375,12 @@ struct RenderableSearch<'a> {
impl<'a> RenderableSearch<'a> { impl<'a> RenderableSearch<'a> {
/// Create a new renderable search iterator. /// Create a new renderable search iterator.
fn new<T>(term: &'a Term<T>) -> Self { fn new<T>(term: &'a Term<T>) -> Self {
// Avoid constructing search if there is none.
if term.regex_search.is_none() {
let iter: MatchIter<'a> = Box::new(iter::empty());
return Self { iter: iter.peekable() };
}
let viewport_end = term.grid().display_offset(); let viewport_end = term.grid().display_offset();
let viewport_start = viewport_end + term.screen_lines().0 - 1; let viewport_start = viewport_end + term.screen_lines().0 - 1;