From 4905aa96b4a22cea9c29faf6fd7afe412b853a95 Mon Sep 17 00:00:00 2001 From: Martchus Date: Fri, 31 Dec 2021 00:44:52 +0100 Subject: [PATCH] Avoid copy when registering interrupt handler --- cli/helper.cpp | 4 ++-- cli/helper.h | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cli/helper.cpp b/cli/helper.cpp index 7da648a..5cc957e 100644 --- a/cli/helper.cpp +++ b/cli/helper.cpp @@ -78,13 +78,13 @@ bool InterruptHandler::s_handlerRegistered = false; * (eg. use POSIX write() instead of std::cout). * \throws Throws std::runtime_error when attempting to create a 2nd instance. */ -InterruptHandler::InterruptHandler(std::function handler) +InterruptHandler::InterruptHandler(std::function &&handler) { // set handler function or throw if an instance has already been created if (s_handler) { throw runtime_error("Only one instance of InterruptHandler can exist at a time."); } - s_handler = handler; + s_handler = std::move(handler); // register handler if not registered yet if (!s_handlerRegistered) { diff --git a/cli/helper.h b/cli/helper.h index 3b929c9..7629f1d 100644 --- a/cli/helper.h +++ b/cli/helper.h @@ -165,7 +165,7 @@ inline FieldValue::FieldValue(DenotationType type, unsigned int fileIndex, const class InterruptHandler { public: - explicit InterruptHandler(std::function handler); + explicit InterruptHandler(std::function &&handler); ~InterruptHandler(); private: