From b204e773d461233aa9b106d32d051333865b2d1b Mon Sep 17 00:00:00 2001 From: Maxime Coste Date: Sun, 13 May 2018 17:24:37 +1000 Subject: [PATCH] Do not push jumps implicitely in transient contexts This should improve performance in draft contexts. --- rc/base/d.kak | 2 +- rc/base/go.kak | 2 +- rc/base/java.kak | 2 +- rc/base/perl.kak | 2 +- src/commands.cc | 11 ++++++----- src/context.hh | 6 +++++- src/normal.cc | 2 +- 7 files changed, 16 insertions(+), 11 deletions(-) diff --git a/rc/base/d.kak b/rc/base/d.kak index f67eb64a..9cb99516 100644 --- a/rc/base/d.kak +++ b/rc/base/d.kak @@ -100,7 +100,7 @@ define-command -hidden d-indent-on-new-line %~ # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/rc/base/go.kak b/rc/base/go.kak index 8d548e21..89bd3239 100644 --- a/rc/base/go.kak +++ b/rc/base/go.kak @@ -64,7 +64,7 @@ define-command -hidden go-indent-on-new-line %~ # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/rc/base/java.kak b/rc/base/java.kak index 85cd5996..52d9a055 100644 --- a/rc/base/java.kak +++ b/rc/base/java.kak @@ -30,7 +30,7 @@ define-command -hidden java-indent-on-new-line %~ # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after keywords diff --git a/rc/base/perl.kak b/rc/base/perl.kak index de261e48..b3180be7 100644 --- a/rc/base/perl.kak +++ b/rc/base/perl.kak @@ -81,7 +81,7 @@ define-command -hidden perl-indent-on-new-line %~ # align to opening paren of previous line try %{ execute-keys -draft [( \A\([^\n]+\n[^\n]*\n?\z s \A\(\h*.|.\z '' & } # copy // comments prefix - try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } + try %{ execute-keys -draft \;k s ^\h*\K/{2,} yP } # indent after a switch's case/default statements try %[ execute-keys -draft k ^\h*(case|default).*:$ j ] # indent after if|else|while|for diff --git a/src/commands.cc b/src/commands.cc index 089db654..3c78ca04 100644 --- a/src/commands.cc +++ b/src/commands.cc @@ -1650,7 +1650,7 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) size_t timestamp = c.buffer().timestamp(); for (auto& sel : sels) { - c.selections_write_only() = SelectionList{ sels.buffer(), sel, sels.timestamp() }; + c.selections_write_only() = SelectionList{sels.buffer(), sel, sels.timestamp()}; c.selections().update(); func(parser, c); @@ -1669,19 +1669,20 @@ void context_wrap(const ParametersParser& parser, Context& context, Func func) if (not draft) { - c.selections_write_only() = SelectionList(c.buffer(), new_sels); + c.selections_write_only() = SelectionList(c.buffer(), std::move(new_sels)); c.selections().sort_and_merge_overlapping(); } } else { - auto original_jump_list = draft ? Optional{} : c.jump_list(); - auto jump = draft ? Optional{} : c.selections(); + const bool transient = c.flags() & Context::Flags::Transient; + auto original_jump_list = transient ? Optional{} : c.jump_list(); + auto jump = transient ? Optional{} : c.selections(); func(parser, c); // If the jump list got mutated, collapse all jumps into a single one from original selections - if (not draft and c.jump_list() != *original_jump_list) + if (not transient and c.jump_list() != *original_jump_list) { original_jump_list->push(std::move(*jump)); if (c.jump_list() != *original_jump_list) diff --git a/src/context.hh b/src/context.hh index e2903b50..11a9806b 100644 --- a/src/context.hh +++ b/src/context.hh @@ -119,7 +119,11 @@ public: Flags flags() const { return m_flags; } JumpList& jump_list() { return m_jump_list; } - void push_jump() { m_jump_list.push(selections()); } + void push_jump(bool force = false) + { + if (force or not (m_flags & Flags::Transient)) + m_jump_list.push(selections()); + } template void set_last_select(Func&& last_select) { m_last_select = std::forward(last_select); } diff --git a/src/normal.cc b/src/normal.cc index 35a093be..aa7cef98 100644 --- a/src/normal.cc +++ b/src/normal.cc @@ -1522,7 +1522,7 @@ void jump(Context& context, NormalParams params) void push_selections(Context& context, NormalParams) { - context.push_jump(); + context.push_jump(true); context.print_status({ format("saved {} selections", context.selections().size()), context.faces()["Information"] }); }