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>
bb10
Giuseppe D'Angelo 2019-08-05 22:54:33 +02:00
parent d1b099c3e3
commit a52a3b2aa4
1 changed files with 11 additions and 4 deletions

View File

@ -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;
}
/*!