aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2016-02-05 12:43:40 +0100
committerMarc Mutz <marc.mutz@kdab.com>2016-09-16 16:43:08 +0000
commitdb7b59dc12209b8e59ce21cb5ca58d1bca56776d (patch)
treec95a1ee326d438b37f9936c53e6358cc8467e184
parenta0df3d1e783589371dd9f961bd59affea60f7291 (diff)
ivicore: use Q_UNLIKELY for every qWarning() etc
If, after checking a condition, we issue a qWarning() or similar, by definition that check is unlikely to be true. Tell the compiler so it can move the error handling code out of the normal code path to increase the effective icache size. Moved conditional code around where possible so that we could always use Q_UNLIKELY, instead of having to revert to Q_LIKELY here and there. In QIviServiceManagerPrivate::loadServiceBackendInterface() factored the error handling into a separate never-inline function warn() that can be called with tail optimization (jmp, not call). Change-Id: I6ea66da047fa9d9ad7a04629c01483a03ffa05df Reviewed-by: Dominik Holland <dominik.holland@pelagicore.com>
-rw-r--r--src/ivicore/qiviabstractfeature.cpp2
-rw-r--r--src/ivicore/qiviproperty.cpp8
-rw-r--r--src/ivicore/qivipropertyfactory.h2
-rw-r--r--src/ivicore/qiviservicemanager.cpp43
4 files changed, 28 insertions, 27 deletions
diff --git a/src/ivicore/qiviabstractfeature.cpp b/src/ivicore/qiviabstractfeature.cpp
index ebac55d..ad8f52f 100644
--- a/src/ivicore/qiviabstractfeature.cpp
+++ b/src/ivicore/qiviabstractfeature.cpp
@@ -277,7 +277,7 @@ bool QIviAbstractFeature::setServiceObject(QIviServiceObject *so)
//We only want to call clearServiceObject if we are sure that the serviceObject changes
if (!so) {
clearServiceObject();
- } else if (so && !acceptServiceObject(so)) {
+ } else if (Q_UNLIKELY(so && !acceptServiceObject(so))) {
qWarning("ServiceObject is not accepted");
clearServiceObject();
diff --git a/src/ivicore/qiviproperty.cpp b/src/ivicore/qiviproperty.cpp
index a8da811..226b5b2 100644
--- a/src/ivicore/qiviproperty.cpp
+++ b/src/ivicore/qiviproperty.cpp
@@ -58,12 +58,12 @@ QIviPropertyPrivate::QIviPropertyPrivate(int userType, QtPrivate::QSlotObjectBas
void QIviPropertyPrivate::throwError(QObject *object, const QString &error)
{
QJSEngine* jsEngine = qjsEngine(object);
- if (jsEngine) {
- QV4::ExecutionEngine *v4 = QV8Engine::getV4(jsEngine);
- v4->throwError(error);
- } else {
+ if (Q_UNLIKELY(!jsEngine)) {
qWarning("%s", qPrintable(error));
+ return;
}
+ QV4::ExecutionEngine *v4 = QV8Engine::getV4(jsEngine);
+ v4->throwError(error);
}
/*!
diff --git a/src/ivicore/qivipropertyfactory.h b/src/ivicore/qivipropertyfactory.h
index b40dbc3..ce532e8 100644
--- a/src/ivicore/qivipropertyfactory.h
+++ b/src/ivicore/qivipropertyfactory.h
@@ -116,7 +116,7 @@ public:
QMetaType metaType(userType);
if (metaType.flags() & QMetaType::IsEnumeration) {
const QMetaObject *mo = metaType.metaObject();
- if (!mo)
+ if (Q_UNLIKELY(!mo))
//TODO Do we want to use a qFatal() here or just report a qCritical instead ?
qFatal("The provided enum needs to be declared as Q_ENUM or Q_FLAG");
}
diff --git a/src/ivicore/qiviservicemanager.cpp b/src/ivicore/qiviservicemanager.cpp
index 4d68152..650f6bb 100644
--- a/src/ivicore/qiviservicemanager.cpp
+++ b/src/ivicore/qiviservicemanager.cpp
@@ -110,17 +110,16 @@ void QIviServiceManagerPrivate::searchPlugins()
found = true;
}
}
- if (!found)
- {
+ if (Q_UNLIKELY(!found))
qWarning() << "No plugins found in search path: " << QCoreApplication::libraryPaths().join(QLatin1String(":"));
- }
}
void QIviServiceManagerPrivate::registerBackend(const QString &fileName, const QJsonObject &metaData)
{
QVariantMap backendMetaData = metaData.value(QLatin1String("MetaData")).toVariant().toMap();
- if (backendMetaData[QLatin1String("interfaces")].isNull() || backendMetaData[QLatin1String("interfaces")].toList().isEmpty()) {
+ if (Q_UNLIKELY(backendMetaData[QLatin1String("interfaces")].isNull() ||
+ backendMetaData[QLatin1String("interfaces")].toList().isEmpty())) {
qWarning("PluginManager - Malformed metaData in '%s'. MetaData must contain a list of interfaces", qPrintable(fileName));
return;
}
@@ -208,6 +207,17 @@ void QIviServiceManagerPrivate::addBackend(Backend *backend)
}
}
+namespace {
+Q_NEVER_INLINE
+static QIviServiceInterface *warn(const char *what, const QPluginLoader *loader)
+{
+ qWarning("ServiceManager::serviceObjects - failed to %s '%s'",
+ what, qPrintable(loader->fileName()));
+ delete loader;
+ return Q_NULLPTR;
+}
+} // unnamed namespace
+
QIviServiceInterface *QIviServiceManagerPrivate::loadServiceBackendInterface(struct Backend *backend)
{
if (backend->interface) {
@@ -216,25 +226,16 @@ QIviServiceInterface *QIviServiceManagerPrivate::loadServiceBackendInterface(str
QPluginLoader *loader = new QPluginLoader(backend->metaData[QLatin1String("fileName")].toString());
QObject *plugin = loader->instance();
- if (plugin) {
-
- QIviServiceInterface *backendInterface = qobject_cast<QIviServiceInterface*>(plugin);
- if (backendInterface) {
- backend->interface = backendInterface;
- backend->loader = loader;
- return backend->interface;
- } else {
- qWarning("ServiceManager::serviceObjects - failed to cast to interface from '%s'", qPrintable(loader->fileName()));
- }
-
- } else {
- qWarning("ServiceManager::serviceObjects - failed to load '%s'", qPrintable(loader->fileName()));
- }
+ if (Q_UNLIKELY(!plugin))
+ return warn("load", loader);
- //Only delete the Loader right away if we didn't succeeded with loading the interfaces.
- delete loader;
+ QIviServiceInterface *backendInterface = qobject_cast<QIviServiceInterface*>(plugin);
+ if (Q_UNLIKELY(!backendInterface))
+ return warn("cast to interface from", loader);
- return 0;
+ backend->interface = backendInterface;
+ backend->loader = loader;
+ return backend->interface;
}
/*!