Do not trigger RegisterModified hooks on register about to be restored
This greatly reduces the amount of hooks triggered.
This commit is contained in:
parent
2df6a57201
commit
c2516f02f6
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -11,7 +11,8 @@ namespace Kakoune
|
|||
void StaticRegister::set(Context& context, ConstArrayView<String> values, bool)
|
||||
{
|
||||
m_content.assign(values.begin(), values.end());
|
||||
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
|
||||
if (not m_disable_modified_hook)
|
||||
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
|
||||
}
|
||||
|
||||
ConstArrayView<String> StaticRegister::get(const Context&)
|
||||
|
@ -46,7 +47,8 @@ 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));
|
||||
|
||||
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
|
||||
if (not m_disable_modified_hook)
|
||||
context.hooks().run_hook(Hook::RegisterModified, m_name, context);
|
||||
}
|
||||
|
||||
const String& HistoryRegister::get_main(const Context&, size_t)
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue
Block a user