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/qlayout.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/qlayout.cpp')
-rw-r--r-- | src/widgets/kernel/qlayout.cpp | 22 |
1 files changed, 11 insertions, 11 deletions
diff --git a/src/widgets/kernel/qlayout.cpp b/src/widgets/kernel/qlayout.cpp index b6d87dc17e..eec60b14d0 100644 --- a/src/widgets/kernel/qlayout.cpp +++ b/src/widgets/kernel/qlayout.cpp @@ -129,7 +129,7 @@ QLayout::QLayout(QLayoutPrivate &dd, QLayout *lay, QWidget *w) if (lay) { lay->addItem(this); } else if (w) { - if (w->layout()) { + if (Q_UNLIKELY(w->layout())) { qWarning("QLayout: Attempting to add QLayout \"%ls\" to %s \"%ls\", which" " already has a layout", qUtf16Printable(QObject::objectName()), w->metaObject()->className(), @@ -469,7 +469,7 @@ QWidget *QLayout::parentWidget() const if (!d->topLevel) { if (parent()) { QLayout *parentLayout = qobject_cast<QLayout*>(parent()); - if (!parentLayout) { + if (Q_UNLIKELY(!parentLayout)) { qWarning("QLayout::parentWidget: A layout can only have another layout as a parent."); return 0; } @@ -776,7 +776,7 @@ QLayout::~QLayout() */ void QLayout::addChildLayout(QLayout *l) { - if (l->parent()) { + if (Q_UNLIKELY(l->parent())) { qWarning("QLayout::addChildLayout: layout \"%ls\" already has a parent", qUtf16Printable(l->objectName())); return; @@ -826,7 +826,7 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw) if (QWidget *w = item->widget()) { QWidget *pw = w->parentWidget(); #ifdef QT_DEBUG - if (pw && pw != mw && layoutDebug()) { + if (Q_UNLIKELY(pw && pw != mw && layoutDebug())) { qWarning("QLayout::addChildLayout: widget %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), qUtf16Printable(w->objectName())); } @@ -849,12 +849,12 @@ void QLayoutPrivate::reparentChildWidgets(QWidget *mw) bool QLayoutPrivate::checkWidget(QWidget *widget) const { Q_Q(const QLayout); - if (!widget) { + if (Q_UNLIKELY(!widget)) { qWarning("QLayout: Cannot add a null widget to %s/%ls", q->metaObject()->className(), qUtf16Printable(q->objectName())); return false; } - if (widget == q->parentWidget()) { + if (Q_UNLIKELY(widget == q->parentWidget())) { qWarning("QLayout: Cannot add parent widget %s/%ls to its child layout %s/%ls", widget->metaObject()->className(), qUtf16Printable(widget->objectName()), q->metaObject()->className(), qUtf16Printable(q->objectName())); @@ -870,12 +870,12 @@ bool QLayoutPrivate::checkWidget(QWidget *widget) const bool QLayoutPrivate::checkLayout(QLayout *otherLayout) const { Q_Q(const QLayout); - if (!otherLayout) { + if (Q_UNLIKELY(!otherLayout)) { qWarning("QLayout: Cannot add a null layout to %s/%ls", q->metaObject()->className(), qUtf16Printable(q->objectName())); return false; } - if (otherLayout == q) { + if (Q_UNLIKELY(otherLayout == q)) { qWarning("QLayout: Cannot add layout %s/%ls to itself", q->metaObject()->className(), qUtf16Printable(q->objectName())); return false; @@ -902,7 +902,7 @@ void QLayout::addChildWidget(QWidget *w) QLayout *l = pw->layout(); if (l && removeWidgetRecursively(l, w)) { #ifdef QT_DEBUG - if (layoutDebug()) + if (Q_UNLIKELY(layoutDebug())) qWarning("QLayout::addChildWidget: %s \"%ls\" is already in a layout; moved to new layout", w->metaObject()->className(), qUtf16Printable(w->objectName())); #endif @@ -910,7 +910,7 @@ void QLayout::addChildWidget(QWidget *w) } if (pw && mw && pw != mw) { #ifdef QT_DEBUG - if (layoutDebug()) + if (Q_UNLIKELY(layoutDebug())) qWarning("QLayout::addChildWidget: %s \"%ls\" in wrong parent; moved to correct parent", w->metaObject()->className(), qUtf16Printable(w->objectName())); #endif @@ -1064,7 +1064,7 @@ bool QLayout::activate() if (d->activated) return false; QWidget *mw = static_cast<QWidget*>(parent()); - if (mw == 0) { + if (Q_UNLIKELY(!mw)) { qWarning("QLayout::activate: %s \"%ls\" does not have a main widget", metaObject()->className(), qUtf16Printable(objectName())); return false; |