From 51089a5742a79467221b5781cb35a8cea023febf Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Nov 2015 10:16:22 +0100 Subject: Use Q_UNLIKELY for every qFatal()/qCritical() If, after checking a condition, we issue a qFatal() or a qCritical(), 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 some cases, simplified the expressions newly wrapped in Q_UNLIKELY as a drive-by. Change-Id: I67537d62b04bc6977d69254690c5ebbdf98bfd6d Reviewed-by: Konstantin Ritt Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/gui/kernel/qguiapplication.cpp | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/gui/kernel/qguiapplication.cpp') diff --git a/src/gui/kernel/qguiapplication.cpp b/src/gui/kernel/qguiapplication.cpp index 248a7d0d1d..f88f6dc01a 100644 --- a/src/gui/kernel/qguiapplication.cpp +++ b/src/gui/kernel/qguiapplication.cpp @@ -1065,9 +1065,7 @@ static void init_platform(const QString &pluginArgument, const QString &platform // Create the platform integration. QGuiApplicationPrivate::platform_integration = QPlatformIntegrationFactory::create(name, arguments, argc, argv, platformPluginPath); - if (QGuiApplicationPrivate::platform_integration) { - QGuiApplicationPrivate::platform_name = new QString(name); - } else { + if (Q_UNLIKELY(!QGuiApplicationPrivate::platform_integration)) { QStringList keys = QPlatformIntegrationFactory::keys(platformPluginPath); QString fatalMessage @@ -1087,6 +1085,8 @@ static void init_platform(const QString &pluginArgument, const QString &platform return; } + QGuiApplicationPrivate::platform_name = new QString(name); + // Many platforms have created QScreens at this point. Finish initializing // QHighDpiScaling to be prepared for early calls to qt_defaultDpi(). if (QGuiApplication::primaryScreen()) { @@ -1414,16 +1414,16 @@ void QGuiApplicationPrivate::init() if (loadTestability) { QLibrary testLib(QStringLiteral("qttestability")); - if (testLib.load()) { + if (Q_UNLIKELY(!testLib.load())) { + qCritical() << "Library qttestability load failed:" << testLib.errorString(); + } else { typedef void (*TasInitialize)(void); TasInitialize initFunction = (TasInitialize)testLib.resolve("qt_testability_init"); - if (initFunction) { - initFunction(); - } else { + if (Q_UNLIKELY(!initFunction)) { qCritical() << "Library qttestability resolve failed!"; + } else { + initFunction(); } - } else { - qCritical() << "Library qttestability load failed:" << testLib.errorString(); } } #else -- cgit v1.2.3