summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qmdiarea.cpp
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@kdab.com>2015-11-12 10:16:22 +0100
committerMarc Mutz <marc.mutz@kdab.com>2015-11-21 14:26:07 +0000
commit496823b9a856d649c468d03b64241562807f3c16 (patch)
tree764f3128688f1d7a6f26a5909ad34b31712ae3a8 /src/widgets/widgets/qmdiarea.cpp
parentf5a650735ea6658a53b3783cc52fe3dcdef40698 (diff)
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) <ogoffart@woboq.com>
Diffstat (limited to 'src/widgets/widgets/qmdiarea.cpp')
-rw-r--r--src/widgets/widgets/qmdiarea.cpp20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/widgets/widgets/qmdiarea.cpp b/src/widgets/widgets/qmdiarea.cpp
index 1864b42a80..55ae866358 100644
--- a/src/widgets/widgets/qmdiarea.cpp
+++ b/src/widgets/widgets/qmdiarea.cpp
@@ -179,7 +179,7 @@ using namespace QMdi;
// Asserts in debug mode, gives warning otherwise.
static bool sanityCheck(const QMdiSubWindow * const child, const char *where)
{
- if (!child) {
+ if (Q_UNLIKELY(!child)) {
const char error[] = "null pointer";
Q_ASSERT_X(false, where, error);
qWarning("%s:%s", where, error);
@@ -190,13 +190,13 @@ static bool sanityCheck(const QMdiSubWindow * const child, const char *where)
static bool sanityCheck(const QList<QWidget *> &widgets, const int index, const char *where)
{
- if (index < 0 || index >= widgets.size()) {
+ if (Q_UNLIKELY(index < 0 || index >= widgets.size())) {
const char error[] = "index out of range";
Q_ASSERT_X(false, where, error);
qWarning("%s:%s", where, error);
return false;
}
- if (!widgets.at(index)) {
+ if (Q_UNLIKELY(!widgets.at(index))) {
const char error[] = "null pointer";
Q_ASSERT_X(false, where, error);
qWarning("%s:%s", where, error);
@@ -1831,12 +1831,12 @@ void QMdiArea::setActiveSubWindow(QMdiSubWindow *window)
return;
}
- if (d->childWindows.isEmpty()) {
+ if (Q_UNLIKELY(d->childWindows.isEmpty())) {
qWarning("QMdiArea::setActiveSubWindow: workspace is empty");
return;
}
- if (d->childWindows.indexOf(window) == -1) {
+ if (Q_UNLIKELY(d->childWindows.indexOf(window) == -1)) {
qWarning("QMdiArea::setActiveSubWindow: window is not inside workspace");
return;
}
@@ -1960,7 +1960,7 @@ void QMdiArea::activatePreviousSubWindow()
*/
QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFlags)
{
- if (!widget) {
+ if (Q_UNLIKELY(!widget)) {
qWarning("QMdiArea::addSubWindow: null pointer to widget");
return 0;
}
@@ -1972,7 +1972,7 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
// Widget is already a QMdiSubWindow
if (child) {
- if (d->childWindows.indexOf(child) != -1) {
+ if (Q_UNLIKELY(d->childWindows.indexOf(child) != -1)) {
qWarning("QMdiArea::addSubWindow: window is already added");
return child;
}
@@ -2003,7 +2003,7 @@ QMdiSubWindow *QMdiArea::addSubWindow(QWidget *widget, Qt::WindowFlags windowFla
*/
void QMdiArea::removeSubWindow(QWidget *widget)
{
- if (!widget) {
+ if (Q_UNLIKELY(!widget)) {
qWarning("QMdiArea::removeSubWindow: null pointer to widget");
return;
}
@@ -2014,7 +2014,7 @@ void QMdiArea::removeSubWindow(QWidget *widget)
if (QMdiSubWindow *child = qobject_cast<QMdiSubWindow *>(widget)) {
int index = d->childWindows.indexOf(child);
- if (index == -1) {
+ if (Q_UNLIKELY(index == -1)) {
qWarning("QMdiArea::removeSubWindow: window is not inside workspace");
return;
}
@@ -2038,7 +2038,7 @@ void QMdiArea::removeSubWindow(QWidget *widget)
}
}
- if (!found)
+ if (Q_UNLIKELY(!found))
qWarning("QMdiArea::removeSubWindow: widget is not child of any window inside QMdiArea");
}