summaryrefslogtreecommitdiffstats
path: root/src/libs/kdtools
diff options
context:
space:
mode:
authorkh1 <karsten.heimrich@digia.com>2014-09-16 12:58:35 +0200
committerKarsten Heimrich <karsten.heimrich@digia.com>2014-10-30 16:36:57 +0100
commit0efa59576fe87664388ef7b2c2107a9b42784239 (patch)
tree392a3287b08d82b6b442d8181204498a627843c1 /src/libs/kdtools
parent37785d75c9fb44f4a78053b198b6065f6150d9ae (diff)
Optimize the lookup and correct some debug information.
Change-Id: I8b5a641a9e551e0e01dce7b4d03b77a20dc156ba Reviewed-by: Kai Koehne <kai.koehne@theqtcompany.com>
Diffstat (limited to 'src/libs/kdtools')
-rw-r--r--src/libs/kdtools/kdupdaterupdatefinder.cpp50
1 files changed, 29 insertions, 21 deletions
diff --git a/src/libs/kdtools/kdupdaterupdatefinder.cpp b/src/libs/kdtools/kdupdaterupdatefinder.cpp
index 177fe2203..2c14d9825 100644
--- a/src/libs/kdtools/kdupdaterupdatefinder.cpp
+++ b/src/libs/kdtools/kdupdaterupdatefinder.cpp
@@ -116,7 +116,7 @@ public:
};
UpdateFinder *q;
Application *application;
- QList<Update *> updates;
+ QHash<QString, Update *> updates;
// Temporary structure that notes down information about updates.
bool cancel;
@@ -132,7 +132,7 @@ public:
QList<UpdateInfo> applicableUpdates(UpdatesInfo *updatesInfo);
void createUpdateObjects(const UpdateSourceInfo &sourceInfo, const QList<UpdateInfo> &updateInfoList);
- bool checkForUpdatePriority(const UpdateSourceInfo &sourceInfo, const UpdateInfo &updateInfo);
+ bool checkPriorityAndVersion(const UpdateSourceInfo &sourceInfo, const QVariantHash &data);
void slotDownloadDone();
};
@@ -422,40 +422,48 @@ void UpdateFinder::Private::createUpdateObjects(const UpdateSourceInfo &sourceIn
const QList<UpdateInfo> &updateInfoList)
{
foreach (const UpdateInfo &info, updateInfoList) {
- // If another update of the same name exists, then use the update coming from a higher priority.
- if (!checkForUpdatePriority(sourceInfo, info)) {
- qDebug().nospace() << "Skipping Update \"" << info.data.value(QLatin1String("Name")).toString()
- << "\" from \"" << sourceInfo.name << "\"(\"" << sourceInfo.url.toString()
- << "\") because an update with the same name was found from a higher priority location";
+ if (!checkPriorityAndVersion(sourceInfo, info.data))
continue;
- }
// Create and register the update
- this->updates.append(new Update(sourceInfo.priority, sourceInfo.url, info.data));
+ updates.insert(info.data.value(QLatin1String("Name")).toString(),
+ new Update(sourceInfo.priority, sourceInfo.url, info.data));
}
}
-bool UpdateFinder::Private::checkForUpdatePriority(const UpdateSourceInfo &sourceInfo, const UpdateInfo &updateInfo)
-{
- for (int i = 0; i < this->updates.count(); i++){
- Update *update = this->updates.at(i);
- if (update->data(QLatin1String("Name")).toString() != updateInfo.data.value(QLatin1String("Name")).toString())
- continue;
+/*
+ If another update of the same name exists, then use the update coming from a higher
+ priority. If the priority is equal or higher, use the update with the higher version.
+ TODO: Fix the case when the priority is less but the version is higher? Behavior change?
+*/
+bool UpdateFinder::Private::checkPriorityAndVersion(const UpdateSourceInfo &sourceInfo,
+ const QVariantHash &data)
+{
+ const QString name = data.value(QLatin1String("Name")).toString();
+ if (Update *update = updates.value(name)) {
// Bingo, update was previously found elsewhere.
// If the existing update comes from a higher priority server, then cool :)
- if (update->priority() > sourceInfo.priority)
+ if (update->priority() > sourceInfo.priority) {
+ qDebug().nospace() << "Skipping Update \"" << name
+ << "\" from \"" << sourceInfo.name << "\"(\"" << sourceInfo.url.toString()
+ << "\") because an update with the same name was found from a higher priority "
+ "location";
return false;
+ }
// If the existing update has a higher version number, keep it
- if (KDUpdater::compareVersion(update->data(QLatin1String("Version")).toString(), updateInfo.data
+ if (KDUpdater::compareVersion(update->data(QLatin1String("Version")).toString(), data
.value(QLatin1String("Version")).toString()) > 0) {
- return false;
+ qDebug().nospace() << "Skipping Update \"" << name
+ << "\" from \"" << sourceInfo.name << "\"(\"" << sourceInfo.url.toString()
+ << "\") because an update with the same name but a higher version exists "
+ "already";
+ return false;
}
// Otherwise the old update must be deleted.
- this->updates.removeAll(update);
- delete update;
+ delete updates.take(name);
return true;
}
@@ -492,7 +500,7 @@ UpdateFinder::~UpdateFinder()
*/
QList<Update *> UpdateFinder::updates() const
{
- return d->updates;
+ return d->updates.values();
}
/*!