From cea7a87d5fe482afa83a8b610b5b39ce83ab27c9 Mon Sep 17 00:00:00 2001 From: Stephen Kelly Date: Thu, 27 Sep 2012 11:22:25 +0200 Subject: [PATCH] Take a QPersistentIndex out of the container instead of casting it. These indexes are later used as the boundary points of a QItemSelectionRange anyway, which means that they're going to become QPersistentModelIndexes again soon. Because QPersistentModelIndex::row and ::column API are not inline, we cache the resulting values in the loop. Change-Id: Ib5099148269a8ccbb7ff2d8819a347e429c55dd1 Reviewed-by: Marc Mutz --- .../itemmodels/qitemselectionmodel.cpp | 24 +++++++++++++------ 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index d55cbe9d97..74bc0e6a9d 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -852,16 +852,26 @@ static QItemSelection mergeIndexes(const QVector &indexes // merge columns int i = 0; while (i < indexes.count()) { - QModelIndex tl = indexes.at(i); - QModelIndex br = tl; + const QPersistentModelIndex &tl = indexes.at(i); + QPersistentModelIndex br = tl; + QModelIndex brParent = br.parent(); + int brRow = br.row(); + int brColumn = br.column(); while (++i < indexes.count()) { - QModelIndex next = indexes.at(i); - if ((next.parent() == br.parent()) - && (next.row() == br.row()) - && (next.column() == br.column() + 1)) + const QPersistentModelIndex &next = indexes.at(i); + const QModelIndex nextParent = next.parent(); + const int nextRow = next.row(); + const int nextColumn = next.column(); + if ((nextParent == brParent) + && (nextRow == brRow) + && (nextColumn == brColumn + 1)) { br = next; - else + brParent = nextParent; + brRow = nextRow; + brColumn = nextColumn; + } else { break; + } } colSpans.append(QItemSelectionRange(tl, br)); }