From da0a93b24bc7158ac82d7659ce036636ef3957e0 Mon Sep 17 00:00:00 2001 From: Johannes Altmanninger Date: Wed, 25 Dec 2024 05:13:38 +0100 Subject: [PATCH] Minor optimization in pager_selection_changed --- src/reader.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/reader.rs b/src/reader.rs index d7a2676c6..f397982b9 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -22,6 +22,7 @@ use once_cell::sync::Lazy; #[cfg(not(target_has_atomic = "64"))] use portable_atomic::AtomicU64; +use std::borrow::Cow; use std::cell::UnsafeCell; use std::cmp; use std::io::BufReader; @@ -3774,18 +3775,19 @@ fn pager_selection_changed(&mut self) { let mut cursor_pos = self.cycle_cursor_pos; let new_cmd_line = match completion { - None => self.cycle_command_line.clone(), - Some(completion) => completion_apply_to_command_line( + None => Cow::Borrowed(&self.cycle_command_line), + Some(completion) => Cow::Owned(completion_apply_to_command_line( &completion.completion, completion.flags, &self.cycle_command_line, &mut cursor_pos, false, - ), + )), }; // Only update if something changed, to avoid useless edits in the undo history. - if new_cmd_line != self.command_line.text() { + if new_cmd_line.as_utfstr() != self.command_line.text() { + let new_cmd_line = new_cmd_line.into_owned(); self.set_buffer_maintaining_pager(&new_cmd_line, cursor_pos, /*transient=*/ true); } }