QRunnable: Extract Method warnNullCallable()
The warning doesn't depend on the template argument, so factor it into an out-of-line Q_DECL_COLD_FUNCTION. This will automatically mark the is_null check as [[unlikely]], too. As a drive-by, use printf-style qWarning() (expands to less code and doesn't require #include <qdebug.h>). Change-Id: I9ac2d912eb1d4f3d1d9b41d77700bed6d6850b0a Reviewed-by: Allan Sandfeld Jensen <allan.jensen@qt.io>
This commit is contained in:
parent
f7d1dc0eee
commit
3fda04644a
@ -9,6 +9,16 @@ QRunnable::~QRunnable()
|
||||
{
|
||||
}
|
||||
|
||||
/*!
|
||||
\internal
|
||||
Prints a warning and returns nullptr.
|
||||
*/
|
||||
QRunnable *QRunnable::warnNullCallable()
|
||||
{
|
||||
qWarning("Trying to create null QRunnable. This may stop working.");
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
/*!
|
||||
\class QRunnable
|
||||
\inmodule QtCore
|
||||
|
@ -5,7 +5,6 @@
|
||||
#define QRUNNABLE_H
|
||||
|
||||
#include <QtCore/qcompilerdetection.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
#include <functional>
|
||||
#include <type_traits>
|
||||
@ -64,6 +63,9 @@ protected:
|
||||
{
|
||||
}
|
||||
};
|
||||
|
||||
private:
|
||||
static Q_DECL_COLD_FUNCTION QRunnable *warnNullCallable();
|
||||
};
|
||||
|
||||
class QGenericRunnable : public QRunnable
|
||||
@ -105,10 +107,8 @@ QRunnable *QRunnable::create(Callable &&functionToRun)
|
||||
const void *functionPtr = reinterpret_cast<void *>(functionToRun);
|
||||
is_null = !functionPtr;
|
||||
}
|
||||
if (is_null) {
|
||||
qWarning() << "Trying to create null QRunnable. This may stop working.";
|
||||
return nullptr;
|
||||
}
|
||||
if (is_null)
|
||||
return warnNullCallable();
|
||||
|
||||
return new QGenericRunnable(
|
||||
new QGenericRunnableHelper<std::decay_t<Callable>>(
|
||||
|
Loading…
Reference in New Issue
Block a user