From 496823b9a856d649c468d03b64241562807f3c16 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Thu, 12 Nov 2015 10:16:22 +0100 Subject: QtWidgets: use Q_UNLIKELY for every qWarning() (1) If, after checking a condition, we issue a qWarning(), 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. This change contains the changes to the util/, dialogs/ and widgets/ subdirs. 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 QSystemTrayIcon::setVisible(), as a drive-by, I swapped the evaluation order of an &&-expression (newly wrapped in Q_UNLIKELY) to be more readable and more efficient (cheaper check first) at the same time. Change-Id: I3564c5a5deacba49d67d3989fb0b53e680c57fcb Reviewed-by: Olivier Goffart (Woboq GmbH) --- src/widgets/widgets/qdialogbuttonbox.cpp | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'src/widgets/widgets/qdialogbuttonbox.cpp') diff --git a/src/widgets/widgets/qdialogbuttonbox.cpp b/src/widgets/widgets/qdialogbuttonbox.cpp index 5b6bfb3b3c..e262f2db22 100644 --- a/src/widgets/widgets/qdialogbuttonbox.cpp +++ b/src/widgets/widgets/qdialogbuttonbox.cpp @@ -405,11 +405,10 @@ QPushButton *QDialogButtonBoxPrivate::createButton(QDialogButtonBox::StandardBut button->setStyle(style); standardButtonHash.insert(button, sbutton); QPlatformDialogHelper::ButtonRole role = QPlatformDialogHelper::buttonRole(static_cast(sbutton)); - if (role != QPlatformDialogHelper::InvalidRole) { - addButton(button, static_cast(role), doLayout); - } else { + if (Q_UNLIKELY(role == QPlatformDialogHelper::InvalidRole)) qWarning("QDialogButtonBox::createButton: Invalid ButtonRole, button not added"); - } + else + addButton(button, static_cast(role), doLayout); #ifdef Q_DEAD_CODE_FROM_QT4_MAC // Since mnemonics is off by default on Mac, we add a Cmd-D @@ -753,7 +752,7 @@ void QDialogButtonBox::removeButton(QAbstractButton *button) void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role) { Q_D(QDialogButtonBox); - if (role <= InvalidRole || role >= NRoles) { + if (Q_UNLIKELY(role <= InvalidRole || role >= NRoles)) { qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); return; } @@ -772,7 +771,7 @@ void QDialogButtonBox::addButton(QAbstractButton *button, ButtonRole role) QPushButton *QDialogButtonBox::addButton(const QString &text, ButtonRole role) { Q_D(QDialogButtonBox); - if (role <= InvalidRole || role >= NRoles) { + if (Q_UNLIKELY(role <= InvalidRole || role >= NRoles)) { qWarning("QDialogButtonBox::addButton: Invalid ButtonRole, button not added"); return 0; } -- cgit v1.2.3