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>
This commit is contained in:
parent
c63de2cda3
commit
552dc1ecfe
@ -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(!member != !slotObj); // one of these must be set, but not both
|
||||||
Q_ASSERT(receiver || slotObj);
|
Q_ASSERT(receiver || slotObj);
|
||||||
Q_ASSERT(!member || receiver); // if member is set, also is receiver
|
Q_ASSERT(!member || receiver); // if member is set, also is receiver
|
||||||
|
const bool isUsingStringBasedSlot = static_cast<bool>(member);
|
||||||
|
|
||||||
if (!QAbstractEventDispatcher::instance(QThread::currentThread())) {
|
if (!QAbstractEventDispatcher::instance(QThread::currentThread())) {
|
||||||
qWarning("QHostInfo::lookupHost() called with no event dispatcher");
|
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"));
|
hostInfo.setErrorString(QCoreApplication::translate("QHostInfo", "No host name given"));
|
||||||
|
|
||||||
QHostInfoResult result(receiver, std::move(slotObj));
|
QHostInfoResult result(receiver, std::move(slotObj));
|
||||||
if (receiver && member)
|
if (isUsingStringBasedSlot) {
|
||||||
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
||||||
receiver, member, Qt::QueuedConnection);
|
receiver, member, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
result.postResultsReady(hostInfo);
|
result.postResultsReady(hostInfo);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
@ -784,9 +786,10 @@ int QHostInfo::lookupHostImpl(const QString &name,
|
|||||||
hostInfo.setLookupId(id);
|
hostInfo.setLookupId(id);
|
||||||
|
|
||||||
QHostInfoResult result(receiver, std::move(slotObj));
|
QHostInfoResult result(receiver, std::move(slotObj));
|
||||||
if (receiver && member)
|
if (isUsingStringBasedSlot) {
|
||||||
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
||||||
receiver, member, Qt::QueuedConnection);
|
receiver, member, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
result.postResultsReady(hostInfo);
|
result.postResultsReady(hostInfo);
|
||||||
#else
|
#else
|
||||||
QHostInfoLookupManager *manager = theHostInfoLookupManager();
|
QHostInfoLookupManager *manager = theHostInfoLookupManager();
|
||||||
@ -800,9 +803,10 @@ int QHostInfo::lookupHostImpl(const QString &name,
|
|||||||
if (valid) {
|
if (valid) {
|
||||||
info.setLookupId(id);
|
info.setLookupId(id);
|
||||||
QHostInfoResult result(receiver, std::move(slotObj));
|
QHostInfoResult result(receiver, std::move(slotObj));
|
||||||
if (receiver && member)
|
if (isUsingStringBasedSlot) {
|
||||||
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
QObject::connect(&result, SIGNAL(resultsReady(QHostInfo)),
|
||||||
receiver, member, Qt::QueuedConnection);
|
receiver, member, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
result.postResultsReady(info);
|
result.postResultsReady(info);
|
||||||
return id;
|
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
|
// cache is not enabled or it was not in the cache, do normal lookup
|
||||||
QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, std::move(slotObj));
|
QHostInfoRunnable *runnable = new QHostInfoRunnable(name, id, receiver, std::move(slotObj));
|
||||||
if (receiver && member)
|
if (isUsingStringBasedSlot) {
|
||||||
QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)),
|
QObject::connect(&runnable->resultEmitter, SIGNAL(resultsReady(QHostInfo)),
|
||||||
receiver, member, Qt::QueuedConnection);
|
receiver, member, Qt::QueuedConnection);
|
||||||
|
}
|
||||||
manager->scheduleLookup(runnable);
|
manager->scheduleLookup(runnable);
|
||||||
}
|
}
|
||||||
#endif // Q_OS_WASM
|
#endif // Q_OS_WASM
|
||||||
|
Loading…
x
Reference in New Issue
Block a user