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;
|
QModelIndex topLeft;
|
||||||
int row = 0;
|
int row = 0;
|
||||||
const int colCount = model->columnCount(root);
|
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)) {
|
if (isHidden(row)) {
|
||||||
//it might be the end of a selection range
|
//it might be the end of a selection range
|
||||||
if (topLeft.isValid()) {
|
if (topLeft.isValid()) {
|
||||||
|
@ -498,11 +498,12 @@ void QTableModel::sort(int column, Qt::SortOrder order)
|
|||||||
{
|
{
|
||||||
QList<QPair<QTableWidgetItem *, int>> sortable;
|
QList<QPair<QTableWidgetItem *, int>> sortable;
|
||||||
QList<int> unsortable;
|
QList<int> unsortable;
|
||||||
|
const int numRows = rowCount();
|
||||||
|
|
||||||
sortable.reserve(rowCount());
|
sortable.reserve(numRows);
|
||||||
unsortable.reserve(rowCount());
|
unsortable.reserve(numRows);
|
||||||
|
|
||||||
for (int row = 0; row < rowCount(); ++row) {
|
for (int row = 0; row < numRows; ++row) {
|
||||||
if (QTableWidgetItem *itm = item(row, column))
|
if (QTableWidgetItem *itm = item(row, column))
|
||||||
sortable.append(QPair<QTableWidgetItem*,int>(itm, row));
|
sortable.append(QPair<QTableWidgetItem*,int>(itm, row));
|
||||||
else
|
else
|
||||||
@ -515,7 +516,6 @@ void QTableModel::sort(int column, Qt::SortOrder order)
|
|||||||
QList<QTableWidgetItem *> sorted_table(tableItems.size());
|
QList<QTableWidgetItem *> sorted_table(tableItems.size());
|
||||||
QModelIndexList from;
|
QModelIndexList from;
|
||||||
QModelIndexList to;
|
QModelIndexList to;
|
||||||
const int numRows = rowCount();
|
|
||||||
const int numColumns = columnCount();
|
const int numColumns = columnCount();
|
||||||
from.reserve(numRows * numColumns);
|
from.reserve(numRows * numColumns);
|
||||||
to.reserve(numRows * numColumns);
|
to.reserve(numRows * numColumns);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user