From 306931349296747eeb469e29908e2ab589de89fd Mon Sep 17 00:00:00 2001 From: Sona Kurazyan Date: Thu, 8 Oct 2020 12:19:13 +0200 Subject: [PATCH] Eliminate the extra copy in QtConcurrent's blocking methods MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-by: MÃ¥rten Nordheim --- src/concurrent/qtconcurrentfilter.h | 32 ++++++++++++++--------------- src/concurrent/qtconcurrentmap.h | 32 ++++++++++++++--------------- 2 files changed, 32 insertions(+), 32 deletions(-) diff --git a/src/concurrent/qtconcurrentfilter.h b/src/concurrent/qtconcurrentfilter.h index a85cbc0224..8a17487466 100644 --- a/src/concurrent/qtconcurrentfilter.h +++ b/src/concurrent/qtconcurrentfilter.h @@ -365,7 +365,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool, { QFuture future = startFilteredReduced( pool, std::forward(sequence), keep, reduce, options); - return future.result(); + return future.takeResult(); } template @@ -377,7 +377,7 @@ ResultType blockingFilteredReduced(Sequence &&sequence, { QFuture future = startFilteredReduced( QThreadPool::globalInstance(), std::forward(sequence), keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced( pool, std::forward(sequence), keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced( QThreadPool::globalInstance(), std::forward(sequence), keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } #ifndef Q_CLANG_QDOC @@ -425,7 +425,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool, { QFuture future = startFilteredReduced( pool, std::forward(sequence), keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced( QThreadPool::globalInstance(), std::forward(sequence), keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced( pool, std::forward(sequence), keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced( QThreadPool::globalInstance(), std::forward(sequence), keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } #endif @@ -489,7 +489,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool, { QFuture future = startFilteredReduced(pool, begin, end, keep, reduce, options); - return future.result(); + return future.takeResult(); } template @@ -502,7 +502,7 @@ ResultType blockingFilteredReduced(Iterator begin, { QFuture future = startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced(pool, begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } #ifndef Q_CLANG_QDOC @@ -551,7 +551,7 @@ ResultType blockingFilteredReduced(QThreadPool *pool, { QFuture future = startFilteredReduced(pool, begin, end, keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, reduce, options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced(pool, begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = startFilteredReduced(QThreadPool::globalInstance(), begin, end, keep, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } #endif diff --git a/src/concurrent/qtconcurrentmap.h b/src/concurrent/qtconcurrentmap.h index e7c188fb8c..2b475dced1 100644 --- a/src/concurrent/qtconcurrentmap.h +++ b/src/concurrent/qtconcurrentmap.h @@ -399,7 +399,7 @@ ResultType blockingMappedReduced(QThreadPool *pool, QFuture future = QtConcurrent::startMappedReduced , ResultType> (pool, std::forward(sequence), map, reduce, options); - return future.result(); + return future.takeResult(); } template @@ -412,7 +412,7 @@ ResultType blockingMappedReduced(Sequence &&sequence, QFuture future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), std::forward(sequence), map, reduce, options); - return future.result(); + return future.takeResult(); } template , ResultType> (pool, std::forward(sequence), map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template , ResultType> (QThreadPool::globalInstance(), std::forward(sequence), map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = QtConcurrent::startMappedReduced , ResultType> (pool, std::forward(sequence), map, reduce, options); - return future.result(); + return future.takeResult(); } template future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), std::forward(sequence), map, reduce, options); - return future.result(); + return future.takeResult(); } template , ResultType> (pool, std::forward(sequence), map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template , ResultType> (QThreadPool::globalInstance(), std::forward(sequence), map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } // blockingMappedReduced() for iterator ranges @@ -529,7 +529,7 @@ ResultType blockingMappedReduced(QThreadPool *pool, QFuture future = QtConcurrent::startMappedReduced , ResultType> (pool, begin, end, map, reduce, options); - return future.result(); + return future.takeResult(); } template @@ -543,7 +543,7 @@ ResultType blockingMappedReduced(Iterator begin, QFuture future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, options); - return future.result(); + return future.takeResult(); } template , ResultType> (pool, begin, end, map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template future = QtConcurrent::startMappedReduced , ResultType> (pool, begin, end, map, reduce, options); - return future.result(); + return future.takeResult(); } template future = QtConcurrent::startMappedReduced , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, options); - return future.result(); + return future.takeResult(); } template , ResultType> (pool, begin, end, map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } template , ResultType> (QThreadPool::globalInstance(), begin, end, map, reduce, ResultType(std::forward(initialValue)), options); - return future.result(); + return future.takeResult(); } // mapped() for sequences with a different putput sequence type.