From 8a1f0d1f6c63f714d100bd49d9f845b5f88f846a Mon Sep 17 00:00:00 2001 From: Christian Ehrlicher Date: Thu, 23 Nov 2017 20:47:22 +0100 Subject: QItemSelectionRange: speedup intersects() in negative case MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit QItemSelectionRange::intersects() needs to check if the parent of both QItemSelectionRanges is the same. This is a very expensive operation which should be done last. Same goes for isValid() which itself calls parent() for two indexes. This rearrangement speeds up some worst-case usecases by at least 30% as shown in the bug report. Task-number: QTBUG-60940 Change-Id: If6111a73cb8b97a8a0d0640527b34448d21f3143 Reviewed-by: Friedemann Kleint Reviewed-by: Thorbjørn Lund Martsum --- src/corelib/itemmodels/qitemselectionmodel.cpp | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/corelib/itemmodels/qitemselectionmodel.cpp b/src/corelib/itemmodels/qitemselectionmodel.cpp index 59a10e9057..9af4fd9133 100644 --- a/src/corelib/itemmodels/qitemselectionmodel.cpp +++ b/src/corelib/itemmodels/qitemselectionmodel.cpp @@ -218,13 +218,15 @@ QT_BEGIN_NAMESPACE */ bool QItemSelectionRange::intersects(const QItemSelectionRange &other) const { - return (isValid() && other.isValid() - && parent() == other.parent() - && model() == other.model() + // isValid() and parent() last since they are more expensive + return (model() == other.model() && ((top() <= other.top() && bottom() >= other.top()) || (top() >= other.top() && top() <= other.bottom())) && ((left() <= other.left() && right() >= other.left()) - || (left() >= other.left() && left() <= other.right()))); + || (left() >= other.left() && left() <= other.right())) + && parent() == other.parent() + && isValid() && other.isValid() + ); } /*! -- cgit v1.2.3