runOnAndroidMainThread(): optimize shared pointer use

- port from QSharedPointer to std::shared_ptr (one instead of two
  atomic ops per shared-pointer copy)

- port to std::make_shared (one instead of two memory allocations for
  shared-pointer + payload creation)

Pick-to: 6.5
Change-Id: Idecef5732d181a63e6936f54204eeb7ecbdc4a0f
Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io>
This commit is contained in:
Marc Mutz 2022-12-22 16:19:13 +01:00 committed by Assam Boudjelthia
parent f46a7698d3
commit dbcbadb7ac

View File

@ -12,6 +12,7 @@
#include <QtCore/qpromise.h>
#include <QtCore/qthreadpool.h>
#include <deque>
#include <memory>
#endif
QT_BEGIN_NAMESPACE
@ -21,7 +22,7 @@ static const char qtNativeClassName[] = "org/qtproject/qt/android/QtNative";
struct PendingRunnable {
std::function<QVariant()> function;
QSharedPointer<QPromise<QVariant>> promise;
std::shared_ptr<QPromise<QVariant>> promise;
};
using PendingRunnables = std::deque<PendingRunnable>;
@ -161,7 +162,7 @@ QFuture<QVariant> QNativeInterface::QAndroidApplication::runOnAndroidMainThread(
const std::function<QVariant()> &runnable,
const QDeadlineTimer timeout)
{
QSharedPointer<QPromise<QVariant>> promise(new QPromise<QVariant>());
auto promise = std::make_shared<QPromise<QVariant>>();
QFuture<QVariant> future = promise->future();
promise->start();