Itemviews: avoid unneeded calls to rowCount()
Avoid unneeded calls to rowCount() in a for loop as this might get expensive for large models. Change-Id: Ic949ba64f5068b4e6ca0d0c9bc51f181e220da70 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> (cherry picked from commit 4280e4c12e289aeb0ed28f07b0036e89bc8fb35f) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
This commit is contained in:
parent
fcd52bf984
commit
5f3e64235e
@ -583,7 +583,8 @@ void QListViewPrivate::selectAll(QItemSelectionModel::SelectionFlags command)
|
||||
QModelIndex topLeft;
|
||||
int row = 0;
|
||||
const int colCount = model->columnCount(root);
|
||||
for(; row < model->rowCount(root); ++row) {
|
||||
const int rowCount = model->rowCount(root);
|
||||
for ( ; row < rowCount; ++row) {
|
||||
if (isHidden(row)) {
|
||||
//it might be the end of a selection range
|
||||
if (topLeft.isValid()) {
|
||||
|
@ -498,11 +498,12 @@ void QTableModel::sort(int column, Qt::SortOrder order)
|
||||
{
|
||||
QList<QPair<QTableWidgetItem *, int>> sortable;
|
||||
QList<int> unsortable;
|
||||
const int numRows = rowCount();
|
||||
|
||||
sortable.reserve(rowCount());
|
||||
unsortable.reserve(rowCount());
|
||||
sortable.reserve(numRows);
|
||||
unsortable.reserve(numRows);
|
||||
|
||||
for (int row = 0; row < rowCount(); ++row) {
|
||||
for (int row = 0; row < numRows; ++row) {
|
||||
if (QTableWidgetItem *itm = item(row, column))
|
||||
sortable.append(QPair<QTableWidgetItem*,int>(itm, row));
|
||||
else
|
||||
@ -515,7 +516,6 @@ void QTableModel::sort(int column, Qt::SortOrder order)
|
||||
QList<QTableWidgetItem *> sorted_table(tableItems.size());
|
||||
QModelIndexList from;
|
||||
QModelIndexList to;
|
||||
const int numRows = rowCount();
|
||||
const int numColumns = columnCount();
|
||||
from.reserve(numRows * numColumns);
|
||||
to.reserve(numRows * numColumns);
|
||||
|
Loading…
x
Reference in New Issue
Block a user