diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-11-12 10:16:22 +0100 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2015-11-25 16:27:11 +0000 |
commit | 0325842b9926f87f22beb3b8dda32c20b2f994ec (patch) | |
tree | 304767b2ae69a9c506e5ce9eef391c414e4a6cf9 /src/widgets/kernel/qstackedlayout.cpp | |
parent | 5645dc9f8a5264bde855d5b14c619198cfedf3a5 (diff) |
QtWidgets: use Q_UNLIKELY for every qWarning() (2)
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 accessible/,
effects/, kernel/, styles/ and itemviews/ 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 QWidgetPrivate::setWindowModified_helper(), 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.
In qDraw* (qdrawutil.cpp), simplified boolean
expressions (sometimes by skipping re-checking
conditions already checked in a previous guard clause).
Change-Id: I58be22be0a33522c2629a66c2f6c795771a99f3f
Reviewed-by: Lars Knoll <lars.knoll@theqtcompany.com>
Diffstat (limited to 'src/widgets/kernel/qstackedlayout.cpp')
-rw-r--r-- | src/widgets/kernel/qstackedlayout.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/src/widgets/kernel/qstackedlayout.cpp b/src/widgets/kernel/qstackedlayout.cpp index 957b6f09b5..b76e92bc35 100644 --- a/src/widgets/kernel/qstackedlayout.cpp +++ b/src/widgets/kernel/qstackedlayout.cpp @@ -57,7 +57,7 @@ QLayoutItem* QStackedLayoutPrivate::replaceAt(int idx, QLayoutItem *newitem) if (idx < 0 || idx >= list.size() || !newitem) return 0; QWidget *wdg = newitem->widget(); - if (!wdg) { + if (Q_UNLIKELY(!wdg)) { qWarning("QStackedLayout::replaceAt: Only widgets can be added"); return 0; } @@ -367,7 +367,7 @@ int QStackedLayout::currentIndex() const void QStackedLayout::setCurrentWidget(QWidget *widget) { int index = indexOf(widget); - if (index == -1) { + if (Q_UNLIKELY(index == -1)) { qWarning("QStackedLayout::setCurrentWidget: Widget %p not contained in stack", widget); return; } @@ -420,12 +420,12 @@ int QStackedLayout::count() const void QStackedLayout::addItem(QLayoutItem *item) { QWidget *widget = item->widget(); - if (widget) { - addWidget(widget); - delete item; - } else { + if (Q_UNLIKELY(!widget)) { qWarning("QStackedLayout::addItem: Only widgets can be added"); + return; } + addWidget(widget); + delete item; } /*! |