From 08410724620d184416133108def8ccc3b3c16525 Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sat, 16 Mar 2019 17:26:42 -0700 Subject: [PATCH] Minor cleanup of kill ring --- src/kill.cpp | 19 ++++++++++--------- src/kill.h | 6 +++--- src/reader.cpp | 9 ++++----- 3 files changed, 17 insertions(+), 17 deletions(-) diff --git a/src/kill.cpp b/src/kill.cpp index b005ba824..89fa8124c 100644 --- a/src/kill.cpp +++ b/src/kill.cpp @@ -17,10 +17,11 @@ typedef std::list kill_list_t; static kill_list_t kill_list; -void kill_add(const wcstring &str) { +void kill_add(wcstring str) { ASSERT_IS_MAIN_THREAD(); - if (str.empty()) return; - kill_list.push_front(str); + if (!str.empty()) { + kill_list.push_front(std::move(str)); + } } /// Remove first match for specified string from circular list. @@ -35,19 +36,19 @@ void kill_replace(const wcstring &old, const wcstring &newv) { kill_add(newv); } -const wchar_t *kill_yank_rotate() { +wcstring kill_yank_rotate() { ASSERT_IS_MAIN_THREAD(); // Move the first element to the end. if (kill_list.empty()) { - return NULL; + return {}; } kill_list.splice(kill_list.end(), kill_list, kill_list.begin()); - return kill_list.front().c_str(); + return kill_list.front(); } -const wchar_t *kill_yank() { +wcstring kill_yank() { if (kill_list.empty()) { - return L""; + return {}; } - return kill_list.front().c_str(); + return kill_list.front(); } diff --git a/src/kill.h b/src/kill.h index e22fb57f6..8e959ca50 100644 --- a/src/kill.h +++ b/src/kill.h @@ -11,12 +11,12 @@ void kill_replace(const wcstring &old, const wcstring &newv); /// Add a string to the top of the killring. -void kill_add(const wcstring &str); +void kill_add(wcstring str); /// Rotate the killring. -const wchar_t *kill_yank_rotate(); +wcstring kill_yank_rotate(); /// Paste from the killring. -const wchar_t *kill_yank(); +wcstring kill_yank(); #endif diff --git a/src/reader.cpp b/src/reader.cpp index d2b4ddbad..f50c4bc5d 100644 --- a/src/reader.cpp +++ b/src/reader.cpp @@ -2391,7 +2391,6 @@ static bool event_is_normal_char(const char_event_t &evt) { maybe_t reader_data_t::readline(int nchars) { int last_char = 0; size_t yank_len = 0; - const wchar_t *yank_str; bool comp_empty = true; std::vector comp; int finished = 0; @@ -2746,18 +2745,18 @@ maybe_t reader_data_t::readline(int nchars) { break; } case R_YANK: { - yank_str = kill_yank(); + wcstring yank_str = kill_yank(); insert_string(active_edit_line(), yank_str); - yank_len = std::wcslen(yank_str); + yank_len = yank_str.size(); break; } case R_YANK_POP: { if (yank_len) { for (size_t i = 0; i < yank_len; i++) remove_backward(); - yank_str = kill_yank_rotate(); + wcstring yank_str = kill_yank_rotate(); insert_string(active_edit_line(), yank_str); - yank_len = std::wcslen(yank_str); + yank_len = yank_str.size(); } break; }