From a996cafeeb3cef23a1ddb0549fb92d19c20962fa Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Mon, 15 Apr 2024 09:46:52 -0700 Subject: [PATCH] Make history::remove take a &wstr instead of a WString While it does need to store the string, we also need to use the string after storing it, so we aren't getting any advantage from passing by value. Just pass by reference to simplify the call sites. --- src/builtins/history.rs | 4 ++-- src/history.rs | 6 +++--- src/reader.rs | 5 ++--- src/tests/history.rs | 2 +- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/builtins/history.rs b/src/builtins/history.rs index 8f99a518b..04158f4d0 100644 --- a/src/builtins/history.rs +++ b/src/builtins/history.rs @@ -307,8 +307,8 @@ pub fn history(parser: &Parser, streams: &mut IoStreams, args: &mut [&wstr]) -> return STATUS_INVALID_ARGS; } - for &delete_string in args { - history.remove(delete_string.to_owned()); + for delete_string in args { + history.remove(delete_string); } } HistCmd::HIST_CLEAR => { diff --git a/src/history.rs b/src/history.rs index e94a8e830..63910b885 100644 --- a/src/history.rs +++ b/src/history.rs @@ -1015,9 +1015,9 @@ fn is_empty(&mut self) -> bool { } /// Remove a history item. - fn remove(&mut self, str_to_remove: WString) { + fn remove(&mut self, str_to_remove: &wstr) { // Add to our list of deleted items. - self.deleted_items.insert(str_to_remove.clone(), false); + self.deleted_items.insert(str_to_remove.to_owned(), false); for idx in (0..self.new_items.len()).rev() { let matched = self.new_items[idx].str() == str_to_remove; @@ -1528,7 +1528,7 @@ pub fn is_empty(&self) -> bool { } /// Remove a history item. - pub fn remove(&self, s: WString) { + pub fn remove(&self, s: &wstr) { self.imp().remove(s) } diff --git a/src/reader.rs b/src/reader.rs index 32f7fe097..4bce967db 100644 --- a/src/reader.rs +++ b/src/reader.rs @@ -2566,8 +2566,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { rl::HistoryPagerDelete => { // Also applies to ordinary history search. if !self.history_search.is_at_end() { - self.history - .remove(self.history_search.current_result().to_owned()); + self.history.remove(self.history_search.current_result()); self.history.save(); self.history_search.handle_deletion(); self.update_command_line_from_history_search(); @@ -2582,7 +2581,7 @@ fn handle_readline_command(&mut self, c: ReadlineCmd) { if let Some(completion) = self.pager.selected_completion(&self.current_page_rendering) { - self.history.remove(completion.completion.clone()); + self.history.remove(&completion.completion); self.history.save(); self.fill_history_pager( HistoryPagerInvocation::Refresh, diff --git a/src/tests/history.rs b/src/tests/history.rs index 543875250..8b27f418a 100644 --- a/src/tests/history.rs +++ b/src/tests/history.rs @@ -147,7 +147,7 @@ macro_rules! test_history_matches { // Test item removal case-sensitive. let mut searcher = HistorySearch::new(history.clone(), L!("Alpha").to_owned()); test_history_matches!(searcher, vec![L!("Alpha")]); - history.remove(L!("Alpha").to_owned()); + history.remove(L!("Alpha")); let mut searcher = HistorySearch::new(history.clone(), L!("Alpha").to_owned()); test_history_matches!(searcher, vec![]);