Eliminate the extra copy in QtConcurrent's blocking methods

Use QFuture::takeResult() instead of QFuture::result() for returning the
resulting sequence from the blocking methods of QtConcurrent.

Change-Id: I0b623ee1ad8bda6789f329dcd63a46acda924539
Reviewed-by: Andrei Golubev <andrei.golubev@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Sona Kurazyan 2020-10-08 12:19:13 +02:00
parent 4a981b9bdb
commit 3069313492
2 changed files with 32 additions and 32 deletions

View File

@ -365,7 +365,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(
pool, std::forward<Sequence>(sequence), keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor>
@ -377,7 +377,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -394,7 +394,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
QFuture<ResultType> future = startFilteredReduced<ResultType>(
pool, std::forward<Sequence>(sequence), keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -410,7 +410,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
QFuture<ResultType> future = startFilteredReduced<ResultType>(
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
#ifndef Q_CLANG_QDOC
@ -425,7 +425,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(
pool, std::forward<Sequence>(sequence), keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -438,7 +438,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -456,7 +456,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
QFuture<ResultType> future = startFilteredReduced<ResultType>(
pool, std::forward<Sequence>(sequence), keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename Sequence, typename KeepFunctor, typename ReduceFunctor,
@ -473,7 +473,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence,
QFuture<ResultType> future = startFilteredReduced<ResultType>(
QThreadPool::globalInstance(), std::forward<Sequence>(sequence), keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
#endif
@ -489,7 +489,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep,
reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor>
@ -502,7 +502,7 @@ ResultType blockingFilteredReduced(Iterator begin,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
begin, end, keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -519,7 +519,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -535,7 +535,7 @@ ResultType blockingFilteredReduced(Iterator begin,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
begin, end, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
#ifndef Q_CLANG_QDOC
@ -551,7 +551,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep,
reduce, options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -565,7 +565,7 @@ ResultType blockingFilteredReduced(Iterator begin,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
begin, end, keep, reduce, options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -582,7 +582,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(pool, begin, end, keep, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename KeepFunctor, typename ReduceFunctor,
@ -599,7 +599,7 @@ ResultType blockingFilteredReduced(Iterator begin,
{
QFuture<ResultType> future = startFilteredReduced<ResultType>(QThreadPool::globalInstance(),
begin, end, keep, reduce, ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
#endif

View File

@ -399,7 +399,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, std::forward<Sequence>(sequence), map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor>
@ -412,7 +412,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
@ -430,7 +430,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, std::forward<Sequence>(sequence), map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Sequence, typename MapFunctor, typename ReduceFunctor,
@ -447,7 +447,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
@ -462,7 +462,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, std::forward<Sequence>(sequence), map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
@ -476,7 +476,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
@ -495,7 +495,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(pool, std::forward<Sequence>(sequence), map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename MapFunctor, typename ReduceFunctor, typename Sequence,
@ -513,7 +513,7 @@ ResultType blockingMappedReduced(Sequence &&sequence,
<QtPrivate::MapResultType<Sequence, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), std::forward<Sequence>(sequence), map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
// blockingMappedReduced() for iterator ranges
@ -529,7 +529,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor>
@ -543,7 +543,7 @@ ResultType blockingMappedReduced(Iterator begin,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -562,7 +562,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options);
return future.result();
return future.takeResult();
}
template <typename ResultType, typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -580,7 +580,7 @@ ResultType blockingMappedReduced(Iterator begin,
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -596,7 +596,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -611,7 +611,7 @@ ResultType blockingMappedReduced(Iterator begin,
QFuture<ResultType> future = QtConcurrent::startMappedReduced
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce, options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -631,7 +631,7 @@ ResultType blockingMappedReduced(QThreadPool *pool,
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(pool, begin, end, map, reduce, ResultType(std::forward<InitialValueType>(initialValue)),
options);
return future.result();
return future.takeResult();
}
template <typename Iterator, typename MapFunctor, typename ReduceFunctor,
@ -650,7 +650,7 @@ ResultType blockingMappedReduced(Iterator begin,
<QtPrivate::MapResultType<Iterator, MapFunctor>, ResultType>
(QThreadPool::globalInstance(), begin, end, map, reduce,
ResultType(std::forward<InitialValueType>(initialValue)), options);
return future.result();
return future.takeResult();
}
// mapped() for sequences with a different putput sequence type.