Do not trigger RegisterModified hooks on register about to be restored

This greatly reduces the amount of hooks triggered.
This commit is contained in:
Maxime Coste 2020-07-21 20:27:42 +10:00
parent 2df6a57201
commit c2516f02f6
4 changed files with 18 additions and 4 deletions

View File

@ -1818,10 +1818,11 @@ void context_wrap(const ParametersParser& parser, Context& context, StringView d
const auto& register_manager = RegisterManager::instance();
auto make_register_restorer = [&](char c) {
return on_scope_end([&, c, save=register_manager[c].save(context)] {
auto& reg = register_manager[c];
return on_scope_end([&, c, save=reg.save(context), d=ScopedSetBool{reg.modified_hook_disabled()}] {
try
{
RegisterManager::instance()[c].restore(context, save);
reg.restore(context, save);
}
catch (runtime_error& err)
{

View File

@ -11,6 +11,7 @@ namespace Kakoune
void StaticRegister::set(Context& context, ConstArrayView<String> values, bool)
{
m_content.assign(values.begin(), values.end());
if (not m_disable_modified_hook)
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
}
@ -46,6 +47,7 @@ void HistoryRegister::set(Context& context, ConstArrayView<String> values, bool
if (current_size > size_limit)
m_content.erase(m_content.begin(), m_content.begin() + (current_size - size_limit));
if (not m_disable_modified_hook)
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
}

View File

@ -26,6 +26,11 @@ public:
using RestoreInfo = Vector<String, MemoryDomain::Registers>;
RestoreInfo save(const Context& context) { return get(context) | gather<RestoreInfo>(); }
void restore(Context& context, const RestoreInfo& info) { set(context, info, true); }
NestedBool& modified_hook_disabled() { return m_disable_modified_hook; }
protected:
NestedBool m_disable_modified_hook;
};
// static value register, which can be modified

View File

@ -107,6 +107,12 @@ struct ScopedSetBool
m_nested_bool.set();
}
ScopedSetBool(ScopedSetBool&& other)
: m_nested_bool(other.m_nested_bool), m_condition(other.m_condition)
{
other.m_condition = false;
}
~ScopedSetBool()
{
if (m_condition)