From a5e028e1b16f1fc802b8dcee26791e8c64ac2aea Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 1 Jun 2014 16:01:38 +0100 Subject: [PATCH] Add Context::set_selections(std::vector) This methods avoids updating the context selection needlessly as they are going to get replaced anyway. --- src/context.cc | 5 +++++ src/context.hh | 1 + src/normal.cc | 8 ++++---- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/context.cc b/src/context.cc index e909f1f5..21704168 100644 --- a/src/context.cc +++ b/src/context.cc @@ -202,6 +202,11 @@ std::vector Context::selections_content() const return contents; } +void Context::set_selections(std::vector sels) +{ + *m_selections = std::move(sels); +} + void Context::begin_edition() { if (m_edition_level >= 0) diff --git a/src/context.hh b/src/context.hh index 90961216..3aa4e0cf 100644 --- a/src/context.hh +++ b/src/context.hh @@ -51,6 +51,7 @@ public: SelectionList& selections(); const SelectionList& selections() const; std::vector selections_content() const; + void set_selections(std::vector sels); void change_buffer(Buffer& buffer); diff --git a/src/normal.cc b/src/normal.cc index 92e5727a..5cc013df 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -725,7 +725,7 @@ void keep(Context& context, int) } if (keep.empty()) throw runtime_error("no selections remaining"); - context.selections() = std::move(keep); + context.set_selections(std::move(keep)); }); } @@ -749,7 +749,7 @@ void keep_pipe(Context& context, int) } if (keep.empty()) throw runtime_error("no selections remaining"); - context.selections() = std::move(keep); + context.set_selections(std::move(keep)); }); } template @@ -1213,7 +1213,7 @@ void undo(Context& context, int) { auto ranges = compute_modified_ranges(buffer, timestamp); if (not ranges.empty()) - context.selections() = std::move(ranges); + context.set_selections(std::move(ranges)); } else if (not res) context.print_status({ "nothing left to undo", get_color("Information") }); @@ -1229,7 +1229,7 @@ void redo(Context& context, int) { auto ranges = compute_modified_ranges(buffer, timestamp); if (not ranges.empty()) - context.selections() = std::move(ranges); + context.set_selections(std::move(ranges)); } else if (not res)