From 413ce9fdb3eea0ba07a64839564a7cf7fb7d0a6f Mon Sep 17 00:00:00 2001 From: Daniel Rainer Date: Sun, 15 Jun 2025 23:16:22 +0200 Subject: [PATCH] Call `cursor_position()` lazily This function does not need to run when the pager is not focused. Calling it lazily eliminates the overhead of calling it when it is not needed. This code runs on each keypress when entering a command, so it makes sense to keep it as lean as possible. (At the very least it avoids spam when trying to debug/analyze gettext behavior.) --- src/reader.rs | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index 189950180..7cf62fd64 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -1553,7 +1553,7 @@ fn is_repaint_needed(&self, mcolors: Option<&[HighlightSpec]>) -> bool { }; let focused_on_pager = self.active_edit_line_tag() == EditableLineTag::SearchField; - let pager_search_field_position = focused_on_pager.then_some(self.pager.cursor_position()); + let pager_search_field_position = focused_on_pager.then(|| self.pager.cursor_position()); let last = &self.rendered_layout; check(self.force_exec_prompt_and_repaint, "forced") || check(self.command_line.text() != last.text, "text") @@ -1603,8 +1603,7 @@ fn make_layout_data(&self) -> LayoutData { result.colors = self.command_line.colors().to_vec(); assert!(result.text.len() == result.colors.len()); result.position = self.command_line.position(); - result.pager_search_field_position = - focused_on_pager.then_some(self.pager.cursor_position()); + result.pager_search_field_position = focused_on_pager.then(|| self.pager.cursor_position()); result.selection = self.selection; result.history_search_range = self.history_search.search_range_if_active(); result.autosuggestion = self.autosuggestion.text.clone();