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/styles | |
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/styles')
-rw-r--r-- | src/widgets/styles/qandroidstyle.cpp | 2 | ||||
-rw-r--r-- | src/widgets/styles/qdrawutil.cpp | 8 | ||||
-rw-r--r-- | src/widgets/styles/qstylesheetstyle.cpp | 8 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsvistastyle.cpp | 4 | ||||
-rw-r--r-- | src/widgets/styles/qwindowsxpstyle.cpp | 8 |
5 files changed, 15 insertions, 15 deletions
diff --git a/src/widgets/styles/qandroidstyle.cpp b/src/widgets/styles/qandroidstyle.cpp index 4489f36ab7..9a0e4ba32a 100644 --- a/src/widgets/styles/qandroidstyle.cpp +++ b/src/widgets/styles/qandroidstyle.cpp @@ -84,7 +84,7 @@ QAndroidStyle::QAndroidStyle() ++objectIterator) { QString key = objectIterator.key(); QJsonValue value = objectIterator.value(); - if (!value.isObject()) { + if (Q_UNLIKELY(!value.isObject())) { qWarning("Style.json structure is unrecognized."); continue; } diff --git a/src/widgets/styles/qdrawutil.cpp b/src/widgets/styles/qdrawutil.cpp index 2a4d392413..d50f04bbb8 100644 --- a/src/widgets/styles/qdrawutil.cpp +++ b/src/widgets/styles/qdrawutil.cpp @@ -87,7 +87,7 @@ void qDrawShadeLine(QPainter *p, int x1, int y1, int x2, int y2, const QPalette &pal, bool sunken, int lineWidth, int midLineWidth) { - if (!(p && lineWidth >= 0 && midLineWidth >= 0)) { + if (Q_UNLIKELY(!p || lineWidth < 0 || midLineWidth < 0)) { qWarning("qDrawShadeLine: Invalid parameters"); return; } @@ -203,7 +203,7 @@ void qDrawShadeRect(QPainter *p, int x, int y, int w, int h, { if (w == 0 || h == 0) return; - if (! (w > 0 && h > 0 && lineWidth >= 0 && midLineWidth >= 0)) { + if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0 || midLineWidth < 0)) { qWarning("qDrawShadeRect: Invalid parameters"); return; } @@ -303,7 +303,7 @@ void qDrawShadePanel(QPainter *p, int x, int y, int w, int h, { if (w == 0 || h == 0) return; - if (!(w > 0 && h > 0 && lineWidth >= 0)) { + if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) { qWarning("qDrawShadePanel: Invalid parameters"); } QColor shade = pal.dark().color(); @@ -509,7 +509,7 @@ void qDrawPlainRect(QPainter *p, int x, int y, int w, int h, const QColor &c, { if (w == 0 || h == 0) return; - if (!(w > 0 && h > 0 && lineWidth >= 0)) { + if (Q_UNLIKELY(w < 0 || h < 0 || lineWidth < 0)) { qWarning("qDrawPlainRect: Invalid parameters"); } QPen oldPen = p->pen(); diff --git a/src/widgets/styles/qstylesheetstyle.cpp b/src/widgets/styles/qstylesheetstyle.cpp index 0c255f231e..40cca059a8 100644 --- a/src/widgets/styles/qstylesheetstyle.cpp +++ b/src/widgets/styles/qstylesheetstyle.cpp @@ -1547,7 +1547,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QObject *obj) const if (ss.startsWith(QLatin1String("file:///"))) ss.remove(0, 8); parser.init(ss, qApp->styleSheet() != ss); - if (!parser.parse(&appSs)) + if (Q_UNLIKELY(!parser.parse(&appSs))) qWarning("Could not parse application stylesheet"); appSs.origin = StyleSheetOrigin_Inline; appSs.depth = 1; @@ -1569,7 +1569,7 @@ QVector<QCss::StyleRule> QStyleSheetStyle::styleRules(const QObject *obj) const parser.init(styleSheet); if (!parser.parse(&ss)) { parser.init(QLatin1String("* {") + styleSheet + QLatin1Char('}')); - if (!parser.parse(&ss)) + if (Q_UNLIKELY(!parser.parse(&ss))) qWarning("Could not parse stylesheet of object %p", o); } ss.origin = StyleSheetOrigin_Inline; @@ -2515,12 +2515,12 @@ void QStyleSheetStyle::setProperties(QWidget *w) const QMetaObject *metaObject = w->metaObject(); int index = metaObject->indexOfProperty(property.toLatin1()); - if (index == -1) { + if (Q_UNLIKELY(index == -1)) { qWarning() << w << " does not have a property named " << property; continue; } const QMetaProperty metaProperty = metaObject->property(index); - if (!metaProperty.isWritable() || !metaProperty.isDesignable()) { + if (Q_UNLIKELY(!metaProperty.isWritable() || !metaProperty.isDesignable())) { qWarning() << w << " cannot design property named " << property; continue; } diff --git a/src/widgets/styles/qwindowsvistastyle.cpp b/src/widgets/styles/qwindowsvistastyle.cpp index a7a0830fb9..3be5ae3524 100644 --- a/src/widgets/styles/qwindowsvistastyle.cpp +++ b/src/widgets/styles/qwindowsvistastyle.cpp @@ -2471,12 +2471,12 @@ bool QWindowsVistaStylePrivate::initTreeViewTheming() return true; m_treeViewHelper = createTreeViewHelperWindow(); - if (!m_treeViewHelper) { + if (Q_UNLIKELY(!m_treeViewHelper)) { qWarning("%s: Unable to create the treeview helper window.", Q_FUNC_INFO); return false; } const HRESULT hr = QWindowsXPStylePrivate::pSetWindowTheme(m_treeViewHelper, L"explorer", NULL); - if (hr != S_OK) { + if (Q_UNLIKELY(hr != S_OK)) { qErrnoWarning("%s: SetWindowTheme() failed.", Q_FUNC_INFO); return false; } diff --git a/src/widgets/styles/qwindowsxpstyle.cpp b/src/widgets/styles/qwindowsxpstyle.cpp index 0b33213378..8bd4f69d20 100644 --- a/src/widgets/styles/qwindowsxpstyle.cpp +++ b/src/widgets/styles/qwindowsxpstyle.cpp @@ -337,14 +337,14 @@ void QWindowsXPStylePrivate::cleanupHandleMap() HTHEME QWindowsXPStylePrivate::createTheme(int theme, HWND hwnd) { - if (theme < 0 || theme >= NThemes || !hwnd) { + if (Q_UNLIKELY(theme < 0 || theme >= NThemes || !hwnd)) { qWarning("%s: Invalid parameters #%d, %p", Q_FUNC_INFO, theme, hwnd); return 0; } if (!m_themes[theme]) { const wchar_t *name = themeNames[theme]; m_themes[theme] = pOpenThemeData(hwnd, name); - if (!m_themes[theme]) + if (Q_UNLIKELY(!m_themes[theme])) qErrnoWarning("%s: OpenThemeData() failed for theme %d (%s).", Q_FUNC_INFO, theme, qPrintable(themeName(theme))); } @@ -504,13 +504,13 @@ HBITMAP QWindowsXPStylePrivate::buffer(int w, int h) GdiFlush(); nullBitmap = (HBITMAP)SelectObject(bufferDC, bufferBitmap); - if (!bufferBitmap) { + if (Q_UNLIKELY(!bufferBitmap)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() failed.", w, h); bufferW = 0; bufferH = 0; return 0; } - if (!bufferPixels) { + if (Q_UNLIKELY(!bufferPixels)) { qErrnoWarning("QWindowsXPStylePrivate::buffer(%dx%d), CreateDIBSection() did not allocate pixel data.", w, h); bufferW = 0; bufferH = 0; |