From 8a0e76c8d8e433d78ee5cfe19bec428623fa9a51 Mon Sep 17 00:00:00 2001 From: Aleksei Bavshin Date: Mon, 19 Oct 2020 18:42:25 -0700 Subject: [PATCH] fix(util): avoid creating temporary functor for each event --- include/util/SafeSignal.hpp | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/include/util/SafeSignal.hpp b/include/util/SafeSignal.hpp index b2beff4a..15a8d2bd 100644 --- a/include/util/SafeSignal.hpp +++ b/include/util/SafeSignal.hpp @@ -8,6 +8,7 @@ #include #include #include +#include namespace waybar { @@ -36,24 +37,26 @@ struct SafeSignal : sigc::signal...)> { protected: using signal_t = sigc::signal...)>; + using slot_t = decltype(std::declval().make_slot()); using arg_tuple_t = std::tuple...>; // ensure that unwrapped methods are not accessible using signal_t::emit_reverse; using signal_t::make_slot; void handle_event() { - auto fn = signal_t::make_slot(); for (std::unique_lock lock(mutex_); !queue_.empty(); lock.lock()) { auto args = queue_.front(); queue_.pop(); lock.unlock(); - std::apply(fn, args); + std::apply(cached_fn_, args); } } Glib::Dispatcher dp_; std::mutex mutex_; std::queue queue_; + // cache functor for signal emission to avoid recreating it on each event + const slot_t cached_fn_ = make_slot(); }; } // namespace waybar