From 3327fccfd534052d7880b12614ab1f3839d84c5c Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 4 May 2023 15:37:30 +0200 Subject: [PATCH] QGenericRunnable: use CompactStorage ...optimizing the storage of empty function objects. Change-Id: I6db7384e1ebb87249d5b93922a6c92f0767cc401 Reviewed-by: Thiago Macieira Reviewed-by: Qt CI Bot --- src/corelib/thread/qrunnable.h | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/corelib/thread/qrunnable.h b/src/corelib/thread/qrunnable.h index 67ce203458..d92eebae24 100644 --- a/src/corelib/thread/qrunnable.h +++ b/src/corelib/thread/qrunnable.h @@ -5,6 +5,7 @@ #define QRUNNABLE_H #include +#include #include #include @@ -54,14 +55,15 @@ protected: }; template - class QGenericRunnableHelper : public QGenericRunnableHelperBase + class QGenericRunnableHelper : public QGenericRunnableHelperBase, + private QtPrivate::CompactStorage { - Callable m_functionToRun; + using Storage = QtPrivate::CompactStorage; static void *impl(Op op, QGenericRunnableHelperBase *that, [[maybe_unused]] void *arg) { const auto _this = static_cast(that); switch (op) { - case Op::Run: _this->m_functionToRun(); break; + case Op::Run: _this->object()(); break; case Op::Destroy: delete _this; break; } return nullptr; @@ -70,7 +72,7 @@ protected: template explicit QGenericRunnableHelper(UniCallable &&functionToRun) noexcept : QGenericRunnableHelperBase(&impl), - m_functionToRun(std::forward(functionToRun)) + Storage{std::forward(functionToRun)} { } };