summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-08-05 22:54:33 +0200
committerGiuseppe D'Angelo <giuseppe.dangelo@kdab.com>2019-08-22 11:40:11 +0200
commita52a3b2aa43870e9b9b76cf628e5e666d7ecc457 (patch)
tree0542eb5539713254622d08f5955c2f55ffc8aab1
parentd1b099c3e3cfcbf86353b53e205c0ebf84cf5592 (diff)
Micro-optimize QAbstractItemModel::setItemData
If b becomes false, we won't call setData ever again. Just bail out the loop early and return in that case. Change-Id: I4b0ed7e21546d686bc3f785209a314a8bed08471 Reviewed-by: Volker Hilsheimer <volker.hilsheimer@qt.io> Reviewed-by: Marc Mutz <marc.mutz@kdab.com>
-rw-r--r--src/corelib/itemmodels/qabstractitemmodel.cpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/src/corelib/itemmodels/qabstractitemmodel.cpp b/src/corelib/itemmodels/qabstractitemmodel.cpp
index c5fb5b9fc5..6e97c2fd39 100644
--- a/src/corelib/itemmodels/qabstractitemmodel.cpp
+++ b/src/corelib/itemmodels/qabstractitemmodel.cpp
@@ -1898,10 +1898,17 @@ bool QAbstractItemModel::clearItemData(const QModelIndex &index)
*/
bool QAbstractItemModel::setItemData(const QModelIndex &index, const QMap<int, QVariant> &roles)
{
- bool b = true;
- for (QMap<int, QVariant>::ConstIterator it = roles.begin(); it != roles.end(); ++it)
- b = b && setData(index, it.value(), it.key());
- return b;
+ // ### Qt 6: Consider change the semantics of this function,
+ // or deprecating/removing it altogether.
+ //
+ // For instance, it should try setting *all* the data
+ // in \a roles, and not bail out at the first setData that returns
+ // false. It should also have a transactional approach.
+ for (auto it = roles.begin(), e = roles.end(); it != e; ++it) {
+ if (!setData(index, it.value(), it.key()))
+ return false;
+ }
+ return true;
}
/*!