diff --git a/src/corelib/thread/qfuture_impl.h b/src/corelib/thread/qfuture_impl.h index 69f57652ea0..b09d84a6d39 100644 --- a/src/corelib/thread/qfuture_impl.h +++ b/src/corelib/thread/qfuture_impl.h @@ -538,11 +538,19 @@ bool Continuation::execute() template struct ContinuationWrapper { - ContinuationWrapper(Function &&f) : function(QSharedPointer::create(std::move(f))) { } - void operator()(const QFutureInterfaceBase &parentData) { (*function)(parentData); } + ContinuationWrapper(Function &&f) : function(std::move(f)) { } + ContinuationWrapper(const ContinuationWrapper &other) + : function(std::move(const_cast(other).function)) + { + Q_ASSERT_X(false, "QFuture", "Continuation shouldn't be copied"); + } + ContinuationWrapper(ContinuationWrapper &&other) = default; + ContinuationWrapper &operator=(ContinuationWrapper &&) = default; + + void operator()(const QFutureInterfaceBase &parentData) { function(parentData); } private: - QSharedPointer function; + Function function; }; template diff --git a/src/corelib/thread/qfutureinterface.cpp b/src/corelib/thread/qfutureinterface.cpp index dfc905e8283..cad6111ab94 100644 --- a/src/corelib/thread/qfutureinterface.cpp +++ b/src/corelib/thread/qfutureinterface.cpp @@ -837,7 +837,7 @@ void QFutureInterfaceBasePrivate::setState(QFutureInterfaceBase::State newState) void QFutureInterfaceBase::setContinuation(std::function func) { - setContinuation(func, nullptr); + setContinuation(std::move(func), nullptr); } void QFutureInterfaceBase::setContinuation(std::function func,