[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-commits
Subject: [ruqola] src: Minor optimization
From: Montel Laurent <null () kde ! org>
Date: 2017-09-01 6:53:45
Message-ID: E1dnfpp-0005M9-0r () code ! kde ! org
[Download RAW message or body]
Git commit f8d80799d96da935467f9c223b82e840961129db by Montel Laurent.
Committed on 01/09/2017 at 06:53.
Pushed by mlaurent into branch 'master'.
Minor optimization
M +6 -4 src/usermodel.cpp
https://commits.kde.org/ruqola/f8d80799d96da935467f9c223b82e840961129db
diff --git a/src/usermodel.cpp b/src/usermodel.cpp
index 1387497..1dc091d 100644
--- a/src/usermodel.cpp
+++ b/src/usermodel.cpp
@@ -63,7 +63,8 @@ QVariant UsersModel::data(const QModelIndex &index, int role) const
User *UsersModel::user(const QString &userId)
{
- for (int i = 0; i < mUsers.count(); ++i) {
+ const int userCount{mUsers.count()};
+ for (int i = 0; i < userCount; ++i) {
if (mUsers.at(i)->userId() == userId) {
return mUsers.at(i);
}
@@ -74,7 +75,8 @@ User *UsersModel::user(const QString &userId)
void UsersModel::removeUser(const QString &userId)
{
qCDebug(RUQOLA_LOG) << " User removed " << userId;
- for (int i = 0; i < mUsers.count(); ++i) {
+ const int userCount{mUsers.count()};
+ for (int i = 0; i < userCount; ++i) {
if (mUsers.at(i)->userId() == userId) {
qCDebug(RUQOLA_LOG) << " User removed " << mUsers.at(i)->name();
beginRemoveRows(QModelIndex(), i, i);
@@ -93,7 +95,6 @@ void UsersModel::addUser(User *user)
qDebug() << "addUser mUsers before"<<mUsers.count();
beginInsertRows(QModelIndex(), pos, pos);
mUsers.append(user);
- //TODO emit signal that we added element
qDebug() << "addUser mUsers after"<<mUsers.count();
endInsertRows();
}
@@ -101,7 +102,8 @@ void UsersModel::addUser(User *user)
void UsersModel::updateUser(const QJsonObject &array)
{
const QString id = array.value(QStringLiteral("id")).toString();
- for (int i = 0; i < mUsers.count(); ++i) {
+ const int userCount{mUsers.count()};
+ for (int i = 0; i < userCount; ++i) {
if (mUsers.at(i)->userId() == id) {
User *user = mUsers.at(i);
const QJsonObject fields = array.value(QStringLiteral("fields")).toObject();
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic