QStandardItemModel: avoid premature pessimization

- don't re-evaluate QMap::end() all the time
- don't copy QVariant more than needed
- pass temporary to QVector::append (enabling moves)
- swap instead of copy-assign a vector into place

Change-Id: I7549812dfbb2dbc9a919fa9565397d50141fc2ca
Reviewed-by: Olivier Goffart (Woboq GmbH) <ogoffart@woboq.com>
This commit is contained in:
Marc Mutz 2015-07-19 11:23:15 +02:00
parent 3d9ccce7d5
commit 24c0ba13fd

View File

@ -198,19 +198,17 @@ void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles)
//let's build the vector of new values //let's build the vector of new values
QVector<QStandardItemData> newValues; QVector<QStandardItemData> newValues;
QMap<int, QVariant>::const_iterator it; for (auto it = roles.begin(), end = roles.end(); it != end; ++it) {
for (it = roles.begin(); it != roles.end(); ++it) { const QVariant &value = it.value();
QVariant value = it.value();
if (value.isValid()) { if (value.isValid()) {
int role = it.key(); int role = it.key();
role = (role == Qt::EditRole) ? Qt::DisplayRole : role; role = (role == Qt::EditRole) ? Qt::DisplayRole : role;
QStandardItemData wid(role,it.value()); newValues.append(QStandardItemData(role, value));
newValues.append(wid);
} }
} }
if (values!=newValues) { if (values!=newValues) {
values=newValues; values.swap(newValues);
if (model) if (model)
model->d_func()->itemChanged(q); model->d_func()->itemChanged(q);
} }