From 94f5ed11a1f82e39e5bc25160deb501efbe67254 Mon Sep 17 00:00:00 2001 From: Anton Kudryavtsev Date: Thu, 11 Feb 2016 10:01:07 +0300 Subject: [PATCH] QStringListModel: optimize container usage. - don't call QList::removeAt() in loop. Just call erase() with two iterators. - don't re-evaluate QList::count() because of result is already cached. Change-Id: I4b3596df4a388f1d39b523c27decad612044cec6 Reviewed-by: Marc Mutz --- src/corelib/itemmodels/qstringlistmodel.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/corelib/itemmodels/qstringlistmodel.cpp b/src/corelib/itemmodels/qstringlistmodel.cpp index 61323ad9c7..1a1b2b9fb6 100644 --- a/src/corelib/itemmodels/qstringlistmodel.cpp +++ b/src/corelib/itemmodels/qstringlistmodel.cpp @@ -237,8 +237,8 @@ bool QStringListModel::removeRows(int row, int count, const QModelIndex &parent) beginRemoveRows(QModelIndex(), row, row + count - 1); - for (int r = 0; r < count; ++r) - lst.removeAt(row); + const auto it = lst.begin() + row; + lst.erase(it, it + count); endRemoveRows(); @@ -274,8 +274,8 @@ void QStringListModel::sort(int, Qt::SortOrder order) std::sort(list.begin(), list.end(), decendingLessThan); lst.clear(); - QVector forwarding(list.count()); - for (int i = 0; i < list.count(); ++i) { + QVector forwarding(lstCount); + for (int i = 0; i < lstCount; ++i) { lst.append(list.at(i).first); forwarding[list.at(i).second] = i; }