diff options
author | Marc Mutz <marc.mutz@kdab.com> | 2015-07-19 11:23:15 +0200 |
---|---|---|
committer | Marc Mutz <marc.mutz@kdab.com> | 2016-02-08 10:21:51 +0000 |
commit | 24c0ba13fd7973a5a9007d4bb651efe714a3c518 (patch) | |
tree | 67ff5384df11197c10bbf35657e662e01f13e2e7 /src/gui/itemmodels | |
parent | 3d9ccce7d52a2f0bdbe73e8f6f25dae045bd09ec (diff) |
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>
Diffstat (limited to 'src/gui/itemmodels')
-rw-r--r-- | src/gui/itemmodels/qstandarditemmodel.cpp | 10 |
1 files changed, 4 insertions, 6 deletions
diff --git a/src/gui/itemmodels/qstandarditemmodel.cpp b/src/gui/itemmodels/qstandarditemmodel.cpp index a09a1d7b1d..e4442bb82f 100644 --- a/src/gui/itemmodels/qstandarditemmodel.cpp +++ b/src/gui/itemmodels/qstandarditemmodel.cpp @@ -198,19 +198,17 @@ void QStandardItemPrivate::setItemData(const QMap<int, QVariant> &roles) //let's build the vector of new values QVector<QStandardItemData> newValues; - QMap<int, QVariant>::const_iterator it; - for (it = roles.begin(); it != roles.end(); ++it) { - QVariant value = it.value(); + for (auto it = roles.begin(), end = roles.end(); it != end; ++it) { + const QVariant &value = it.value(); if (value.isValid()) { int role = it.key(); role = (role == Qt::EditRole) ? Qt::DisplayRole : role; - QStandardItemData wid(role,it.value()); - newValues.append(wid); + newValues.append(QStandardItemData(role, value)); } } if (values!=newValues) { - values=newValues; + values.swap(newValues); if (model) model->d_func()->itemChanged(q); } |