diff options
author | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2017-11-23 20:47:22 +0100 |
---|---|---|
committer | Christian Ehrlicher <ch.ehrlicher@gmx.de> | 2017-11-30 17:29:27 +0000 |
commit | 8a1f0d1f6c63f714d100bd49d9f845b5f88f846a (patch) | |
tree | db45cf8b7d345b8d8fc7618914b8dede35973010 /src | |
parent | f0e9d268c2eafb5ca8897a63f6288097fc280288 (diff) |
QItemSelectionRange: speedup intersects() in negative case
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 <Friedemann.Kleint@qt.io>
Reviewed-by: Thorbjørn Lund Martsum <tmartsum@gmail.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/corelib/itemmodels/qitemselectionmodel.cpp | 10 |
1 files changed, 6 insertions, 4 deletions
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() + ); } /*! |