Pass QFutureInterface by reference

Prevent doing many copies of QFutureInterface when
running async tasks and pass it by reference instead.

Change-Id: Ic49cfd86a6c651b1b94f791d79a40c99703370ec
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Jarek Kobus
2021-08-27 09:45:24 +02:00
parent 25ff15a1fb
commit 390b214198
2 changed files with 12 additions and 12 deletions

View File

@@ -58,7 +58,7 @@ protected:
std::remove_reference_t<typename std::iterator_traits<ForwardIterator>::reference>>; std::remove_reference_t<typename std::iterator_traits<ForwardIterator>::reference>>;
public: public:
MapReduceBase(QFutureInterface<ReduceResult> futureInterface, ForwardIterator begin, ForwardIterator end, MapReduceBase(QFutureInterface<ReduceResult> &futureInterface, ForwardIterator begin, ForwardIterator end,
MapFunction &&map, State &state, ReduceFunction &&reduce, MapFunction &&map, State &state, ReduceFunction &&reduce,
MapReduceOption option, QThreadPool *pool, int size) MapReduceOption option, QThreadPool *pool, int size)
: m_futureInterface(futureInterface), : m_futureInterface(futureInterface),
@@ -165,7 +165,7 @@ protected:
} }
QFutureWatcher<void> m_selfWatcher; QFutureWatcher<void> m_selfWatcher;
QFutureInterface<ReduceResult> m_futureInterface; QFutureInterface<ReduceResult> &m_futureInterface;
ForwardIterator m_iterator; ForwardIterator m_iterator;
const ForwardIterator m_end; const ForwardIterator m_end;
MapFunction m_map; MapFunction m_map;
@@ -188,7 +188,7 @@ class MapReduce : public MapReduceBase<ForwardIterator, MapResult, MapFunction,
{ {
using BaseType = MapReduceBase<ForwardIterator, MapResult, MapFunction, State, ReduceResult, ReduceFunction>; using BaseType = MapReduceBase<ForwardIterator, MapResult, MapFunction, State, ReduceResult, ReduceFunction>;
public: public:
MapReduce(QFutureInterface<ReduceResult> futureInterface, ForwardIterator begin, ForwardIterator end, MapReduce(QFutureInterface<ReduceResult> &futureInterface, ForwardIterator begin, ForwardIterator end,
MapFunction &&map, State &state, ReduceFunction &&reduce, MapReduceOption option, MapFunction &&map, State &state, ReduceFunction &&reduce, MapReduceOption option,
QThreadPool *pool, int size) QThreadPool *pool, int size)
: BaseType(futureInterface, begin, end, std::forward<MapFunction>(map), state, : BaseType(futureInterface, begin, end, std::forward<MapFunction>(map), state,
@@ -237,7 +237,7 @@ class MapReduce<ForwardIterator, void, MapFunction, State, ReduceResult, ReduceF
{ {
using BaseType = MapReduceBase<ForwardIterator, void, MapFunction, State, ReduceResult, ReduceFunction>; using BaseType = MapReduceBase<ForwardIterator, void, MapFunction, State, ReduceResult, ReduceFunction>;
public: public:
MapReduce(QFutureInterface<ReduceResult> futureInterface, ForwardIterator begin, ForwardIterator end, MapReduce(QFutureInterface<ReduceResult> &futureInterface, ForwardIterator begin, ForwardIterator end,
MapFunction &&map, State &state, ReduceFunction &&reduce, MapReduceOption option, MapFunction &&map, State &state, ReduceFunction &&reduce, MapReduceOption option,
QThreadPool *pool, int size) QThreadPool *pool, int size)
: BaseType(futureInterface, begin, end, std::forward<MapFunction>(map), state, : BaseType(futureInterface, begin, end, std::forward<MapFunction>(map), state,

View File

@@ -238,28 +238,28 @@ private:
// void function that does not take QFutureInterface // void function that does not take QFutureInterface
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncReturnVoidDispatch(std::true_type, QFutureInterface<ResultType>, Function &&function, Args&&... args) void runAsyncReturnVoidDispatch(std::true_type, QFutureInterface<ResultType> &, Function &&function, Args&&... args)
{ {
function(std::forward<Args>(args)...); function(std::forward<Args>(args)...);
} }
// non-void function that does not take QFutureInterface // non-void function that does not take QFutureInterface
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncReturnVoidDispatch(std::false_type, QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncReturnVoidDispatch(std::false_type, QFutureInterface<ResultType> &futureInterface, Function &&function, Args&&... args)
{ {
futureInterface.reportResult(function(std::forward<Args>(args)...)); futureInterface.reportResult(function(std::forward<Args>(args)...));
} }
// function that takes QFutureInterface // function that takes QFutureInterface
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncQFutureInterfaceDispatch(std::true_type, QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncQFutureInterfaceDispatch(std::true_type, QFutureInterface<ResultType> &futureInterface, Function &&function, Args&&... args)
{ {
function(futureInterface, std::forward<Args>(args)...); function(futureInterface, std::forward<Args>(args)...);
} }
// function that does not take QFutureInterface // function that does not take QFutureInterface
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface<ResultType> &futureInterface, Function &&function, Args&&... args)
{ {
runAsyncReturnVoidDispatch(std::is_void<std::invoke_result_t<Function, Args...>>(), runAsyncReturnVoidDispatch(std::is_void<std::invoke_result_t<Function, Args...>>(),
futureInterface, std::forward<Function>(function), std::forward<Args>(args)...); futureInterface, std::forward<Function>(function), std::forward<Args>(args)...);
@@ -269,7 +269,7 @@ void runAsyncQFutureInterfaceDispatch(std::false_type, QFutureInterface<ResultTy
template <typename ResultType, typename Function, typename... Args, template <typename ResultType, typename Function, typename... Args,
typename = std::enable_if_t<!std::is_member_pointer<std::decay_t<Function>>::value> typename = std::enable_if_t<!std::is_member_pointer<std::decay_t<Function>>::value>
> >
void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Args&&... args) void runAsyncMemberDispatch(QFutureInterface<ResultType> &futureInterface, Function &&function, Args&&... args)
{ {
runAsyncQFutureInterfaceDispatch(functionTakesArgument<Function, 0, QFutureInterface<ResultType>&>(), runAsyncQFutureInterfaceDispatch(functionTakesArgument<Function, 0, QFutureInterface<ResultType>&>(),
futureInterface, std::forward<Function>(function), std::forward<Args>(args)...); futureInterface, std::forward<Function>(function), std::forward<Args>(args)...);
@@ -279,7 +279,7 @@ void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Functi
template <typename ResultType, typename Function, typename Obj, typename... Args, template <typename ResultType, typename Function, typename Obj, typename... Args,
typename = std::enable_if_t<std::is_member_pointer<std::decay_t<Function>>::value> typename = std::enable_if_t<std::is_member_pointer<std::decay_t<Function>>::value>
> >
void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Function &&function, Obj &&obj, Args&&... args) void runAsyncMemberDispatch(QFutureInterface<ResultType> &futureInterface, Function &&function, Obj &&obj, Args&&... args)
{ {
// Wrap member function with object into callable // Wrap member function with object into callable
runAsyncImpl(futureInterface, runAsyncImpl(futureInterface,
@@ -289,7 +289,7 @@ void runAsyncMemberDispatch(QFutureInterface<ResultType> futureInterface, Functi
// cref to function/callable // cref to function/callable
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncImpl(QFutureInterface<ResultType> futureInterface, void runAsyncImpl(QFutureInterface<ResultType> &futureInterface,
std::reference_wrapper<Function> functionWrapper, Args&&... args) std::reference_wrapper<Function> functionWrapper, Args&&... args)
{ {
runAsyncMemberDispatch(futureInterface, functionWrapper.get(), std::forward<Args>(args)...); runAsyncMemberDispatch(futureInterface, functionWrapper.get(), std::forward<Args>(args)...);
@@ -297,7 +297,7 @@ void runAsyncImpl(QFutureInterface<ResultType> futureInterface,
// function/callable, no cref // function/callable, no cref
template <typename ResultType, typename Function, typename... Args> template <typename ResultType, typename Function, typename... Args>
void runAsyncImpl(QFutureInterface<ResultType> futureInterface, void runAsyncImpl(QFutureInterface<ResultType> &futureInterface,
Function &&function, Args&&... args) Function &&function, Args&&... args)
{ {
runAsyncMemberDispatch(futureInterface, std::forward<Function>(function), runAsyncMemberDispatch(futureInterface, std::forward<Function>(function),