From 552dc1ecfe4695b8f60beacd70358362e09c5e2f Mon Sep 17 00:00:00 2001 From: Giuseppe D'Angelo Date: Mon, 4 Sep 2023 21:17:17 +0200 Subject: [PATCH] QHostInfo::lookupHostImpl: code tidies MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since a non-null `member` implies a non-null `receiver`, streamline the redundant check(s). While at it, introduce a simple boolean that conveys the meaning of what we're checking for. Change-Id: Ib9be162075771de74b1a6bc4426008b7c194df3a Reviewed-by: Thiago Macieira Reviewed-by: Volker Hilsheimer Reviewed-by: MÃ¥rten Nordheim --- src/network/kernel/qhostinfo.cpp | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index fcd3a6963fb..fc36d0a9624 100644 --- a/src/network/kernel/qhostinfo.cpp +++ b/src/network/kernel/qhostinfo.cpp @@ -751,6 +751,7 @@ int QHostInfo::lookupHostImpl(const QString &name, Q_ASSERT(!member != !slotObj); // one of these must be set, but not both Q_ASSERT(receiver || slotObj); Q_ASSERT(!member || receiver); // if member is set, also is receiver + const bool isUsingStringBasedSlot = static_cast(member); if (!QAbstractEventDispatcher::instance(QThread::currentThread())) { qWarning("QHostInfo::lookupHost() called with no event dispatcher"); @@ -767,9 +768,10 @@ int QHostInfo::lookupHostImpl(const QString &name, hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given")); QHostInfoResult result(receiver, std::move(slotObj)); - if (receiver && member) + if (isUsingStringBasedSlot) { QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); + } result.postResultsReady(hostInfo); return id; @@ -784,9 +786,10 @@ int QHostInfo::lookupHostImpl(const QString &name, hostInfo.setLookupId(id); QHostInfoResult result(receiver, std::move(slotObj)); - if (receiver && member) + if (isUsingStringBasedSlot) { QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); + } result.postResultsReady(hostInfo); #else QHostInfoLookupManager *manager = theHostInfoLookupManager(); @@ -800,9 +803,10 @@ int QHostInfo::lookupHostImpl(const QString &name, if (valid) { info.setLookupId(id); QHostInfoResult result(receiver, std::move(slotObj)); - if (receiver && member) + if (isUsingStringBasedSlot) { QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); + } result.postResultsReady(info); return id; } @@ -810,9 +814,10 @@ int QHostInfo::lookupHostImpl(const QString &name, // cache is not enabled or it was not in the cache, do normal lookup QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, std::move(slotObj)); - if (receiver && member) + if (isUsingStringBasedSlot) { QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)), receiver, member, Qt::QueuedConnection); + } manager->scheduleLookup(runnable); } #endif // Q_OS_WASM