diff options
author | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-09-04 21:17:17 +0200 |
---|---|---|
committer | Giuseppe D'Angelo <giuseppe.dangelo@kdab.com> | 2023-09-05 16:34:20 +0200 |
commit | 552dc1ecfe4695b8f60beacd70358362e09c5e2f (patch) | |
tree | 50f35815e155d0a34054bd1e2bb30dd6804c5fd0 /src/network/kernel | |
parent | c63de2cda39f640788786eeb0e95182c3de80e5b (diff) |
QHostInfo::lookupHostImpl: code tidies
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 <thiago.macieira@intel.com>
Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io>
Reviewed-by: MÃ¥rten Nordheim <marten.nordheim@qt.io>
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qhostinfo.cpp | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/src/network/kernel/qhostinfo.cpp b/src/network/kernel/qhostinfo.cpp index fcd3a6963f..fc36d0a962 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<bool>(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 |