From de2840675a0165324f001c83f91589332b7c3265 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 22 Dec 2022 11:02:40 +0100 Subject: [PATCH] QAndroidNaticeInterface: replace a pair with a struct Nicer member names make the code using the type more readable. It also allows to add other members later. Change-Id: I69f1f97673a8f1ad8eb73e4f1e5323eccf929413 Reviewed-by: Assam Boudjelthia (cherry picked from commit b6fdf34dfca20c8312feeb28efd3288700ad4b3c) Reviewed-by: Qt Cherry-pick Bot --- .../android/qandroidnativeinterface.cpp | 23 ++++++++++++------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/corelib/platform/android/qandroidnativeinterface.cpp b/src/corelib/platform/android/qandroidnativeinterface.cpp index 886604d0ab3..d54bc862ddd 100644 --- a/src/corelib/platform/android/qandroidnativeinterface.cpp +++ b/src/corelib/platform/android/qandroidnativeinterface.cpp @@ -19,8 +19,12 @@ QT_BEGIN_NAMESPACE #if QT_CONFIG(future) && !defined(QT_NO_QOBJECT) static const char qtNativeClassName[] = "org/qtproject/qt/android/QtNative"; -typedef std::pair, QSharedPointer>> RunnablePair; -typedef std::deque PendingRunnables; +struct PendingRunnable { + std::function function; + QSharedPointer> promise; +}; + +using PendingRunnables = std::deque; Q_GLOBAL_STATIC(PendingRunnables, g_pendingRunnables); Q_CONSTINIT static QBasicMutex g_pendingRunnablesMutex; #endif @@ -191,7 +195,11 @@ QFuture QNativeInterface::QAndroidApplication::runOnAndroidMainThread( } QMutexLocker locker(&g_pendingRunnablesMutex); - g_pendingRunnables->push_back(std::pair(runnable, promise)); +#ifdef __cpp_aggregate_paren_init + g_pendingRunnables->emplace_back(runnable, std::move(promise)); +#else + g_pendingRunnables->push_back({runnable, std::move(promise)}); +#endif locker.unlock(); QJniObject::callStaticMethod(qtNativeClassName, @@ -209,15 +217,14 @@ static void runPendingCppRunnables(JNIEnv */*env*/, jobject /*obj*/) if (g_pendingRunnables->empty()) break; - std::pair pair = std::move(g_pendingRunnables->front()); + PendingRunnable r = std::move(g_pendingRunnables->front()); g_pendingRunnables->pop_front(); locker.unlock(); // run the runnable outside the sync block! - auto promise = pair.second; - if (!promise->isCanceled()) - promise->addResult(pair.first()); - promise->finish(); + if (!r.promise->isCanceled()) + r.promise->addResult(r.function()); + r.promise->finish(); } } #endif