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/itemviews | |
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/itemviews')
-rw-r--r-- | src/widgets/itemviews/qabstractitemview.cpp | 8 | ||||
-rw-r--r-- | src/widgets/itemviews/qdirmodel.cpp | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qlistview.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qtableview.cpp | 4 | ||||
-rw-r--r-- | src/widgets/itemviews/qtablewidget.cpp | 2 | ||||
-rw-r--r-- | src/widgets/itemviews/qtreewidget.cpp | 4 |
6 files changed, 12 insertions, 12 deletions
diff --git a/src/widgets/itemviews/qabstractitemview.cpp b/src/widgets/itemviews/qabstractitemview.cpp index ad7be840d0..2f7b2a43c4 100644 --- a/src/widgets/itemviews/qabstractitemview.cpp +++ b/src/widgets/itemviews/qabstractitemview.cpp @@ -758,7 +758,7 @@ void QAbstractItemView::setSelectionModel(QItemSelectionModel *selectionModel) Q_ASSERT(selectionModel); Q_D(QAbstractItemView); - if (selectionModel->model() != d->model) { + if (Q_UNLIKELY(selectionModel->model() != d->model)) { qWarning("QAbstractItemView::setSelectionModel() failed: " "Trying to set a selection model, which works on " "a different model than the view."); @@ -1113,7 +1113,7 @@ void QAbstractItemView::reset() void QAbstractItemView::setRootIndex(const QModelIndex &index) { Q_D(QAbstractItemView); - if (index.isValid() && index.model() != d->model) { + if (Q_UNLIKELY(index.isValid() && index.model() != d->model)) { qWarning("QAbstractItemView::setRootIndex failed : index must be from the currently set model"); return; } @@ -1166,9 +1166,9 @@ void QAbstractItemView::selectAll() void QAbstractItemView::edit(const QModelIndex &index) { Q_D(QAbstractItemView); - if (!d->isIndexValid(index)) + if (Q_UNLIKELY(!d->isIndexValid(index))) qWarning("edit: index was invalid"); - if (!edit(index, AllEditTriggers, 0)) + if (Q_UNLIKELY(!edit(index, AllEditTriggers, 0))) qWarning("edit: editing failed"); } diff --git a/src/widgets/itemviews/qdirmodel.cpp b/src/widgets/itemviews/qdirmodel.cpp index 0c157c940f..ddc75ef176 100644 --- a/src/widgets/itemviews/qdirmodel.cpp +++ b/src/widgets/itemviews/qdirmodel.cpp @@ -1022,7 +1022,7 @@ bool QDirModel::rmdir(const QModelIndex &index) return false; QDirModelPrivate::QDirNode *n = d_func()->node(index); - if (!n->info.isDir()) { + if (Q_UNLIKELY(!n->info.isDir())) { qWarning("rmdir: the node is not a directory"); return false; } @@ -1172,7 +1172,7 @@ QDirModelPrivate::QDirNode *QDirModelPrivate::node(int row, QDirNode *parent) co if (isDir && !p->populated) populate(p); // will also resolve symlinks - if (row >= p->children.count()) { + if (Q_UNLIKELY(row >= p->children.count())) { qWarning("node: the row does not exist"); return 0; } diff --git a/src/widgets/itemviews/qlistview.cpp b/src/widgets/itemviews/qlistview.cpp index 9c79509874..ed1f1f2e98 100644 --- a/src/widgets/itemviews/qlistview.cpp +++ b/src/widgets/itemviews/qlistview.cpp @@ -392,7 +392,7 @@ int QListView::spacing() const void QListView::setBatchSize(int batchSize) { Q_D(QListView); - if (batchSize <= 0) { + if (Q_UNLIKELY(batchSize <= 0)) { qWarning("Invalid batchSize (%d)", batchSize); return; } diff --git a/src/widgets/itemviews/qtableview.cpp b/src/widgets/itemviews/qtableview.cpp index 89bd9dbcb1..d0dcb02d7f 100644 --- a/src/widgets/itemviews/qtableview.cpp +++ b/src/widgets/itemviews/qtableview.cpp @@ -669,7 +669,7 @@ void QTableViewPrivate::trimHiddenSelections(QItemSelectionRange *range) const */ void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan) { - if (row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0) { + if (Q_UNLIKELY(row < 0 || column < 0 || rowSpan <= 0 || columnSpan <= 0)) { qWarning("QTableView::setSpan: invalid span given: (%d, %d, %d, %d)", row, column, rowSpan, columnSpan); return; @@ -688,7 +688,7 @@ void QTableViewPrivate::setSpan(int row, int column, int rowSpan, int columnSpan sp->m_right = column + columnSpan - 1; spans.updateSpan(sp, old_height); return; - } else if (rowSpan == 1 && columnSpan == 1) { + } else if (Q_UNLIKELY(rowSpan == 1 && columnSpan == 1)) { qWarning("QTableView::setSpan: single cell span won't be added"); return; } diff --git a/src/widgets/itemviews/qtablewidget.cpp b/src/widgets/itemviews/qtablewidget.cpp index cd38f4b282..901281e17f 100644 --- a/src/widgets/itemviews/qtablewidget.cpp +++ b/src/widgets/itemviews/qtablewidget.cpp @@ -1958,7 +1958,7 @@ void QTableWidget::setItem(int row, int column, QTableWidgetItem *item) { Q_D(QTableWidget); if (item) { - if (item->view != 0) { + if (Q_UNLIKELY(item->view)) { qWarning("QTableWidget: cannot insert an item that is already owned by another QTableWidget"); } else { item->view = this; diff --git a/src/widgets/itemviews/qtreewidget.cpp b/src/widgets/itemviews/qtreewidget.cpp index 676893ebf0..748d899dd0 100644 --- a/src/widgets/itemviews/qtreewidget.cpp +++ b/src/widgets/itemviews/qtreewidget.cpp @@ -3280,14 +3280,14 @@ QMimeData *QTreeWidget::mimeData(const QList<QTreeWidgetItem*> items) const QList<QModelIndex> indexes; for (int i = 0; i < items.count(); ++i) { QTreeWidgetItem *item = items.at(i); - if (!item) { + if (Q_UNLIKELY(!item)) { qWarning("QTreeWidget::mimeData: Null-item passed"); return 0; } for (int c = 0; c < item->values.count(); ++c) { const QModelIndex index = indexFromItem(item, c); - if (!index.isValid()) { + if (Q_UNLIKELY(!index.isValid())) { qWarning() << "QTreeWidget::mimeData: No index associated with item :" << item; return 0; } |