Commit be30e11c authored by Fabian Kosmale's avatar Fabian Kosmale Committed by Fabian Kosmale

fix clazy warning: container-anti-pattern

parent 5ef63eab
......@@ -85,7 +85,8 @@ struct ConcurrentOrphanQuery
allPackages[ pkg->name() ] = pkg;
}
foreach (Package* pkg, allPackages.values()) {
for (auto it = allPackages.constBegin() , end = allPackages.constEnd(); it != end; ++it) {
auto pkg = it.value();
if (pkg->installReason() == Package::ExplicitlyInstalledReason) {
Package::List stack;
......
......@@ -118,9 +118,11 @@ void ErrorQueue::appendError(const Error& error)
QWriteLocker locker(d->mutex);
d->errorQueue.enqueue(error);
foreach (ErrorHandler* registeredHandler, d->errorSlots.values( error.type() )) {
for (auto it = d->errorSlots.constFind( error.type() ), end = d->errorSlots.constEnd(); it != end && it.key() == error.type(); ++it ) {
ErrorHandler* registeredHandler = it.value();
QMetaObject::invokeMethod(registeredHandler->receiver(), registeredHandler->slot(), Qt::QueuedConnection);
}
}
void ErrorQueue::appendErrors(const Error::List& errors)
......@@ -245,4 +247,4 @@ Error::Type Error::type() const
return d->type;
}
}
\ No newline at end of file
}
......@@ -903,7 +903,8 @@ Delta* Package::retrieveDeltaFrom(const Version &version)
locker.unlock();
retrieveDeltas();
locker.relock();
foreach (Delta *del, d->deltaCache.values()) {
for (auto it = d->deltaCache.constBegin(), end = d->deltaCache.constEnd(); it != end; ++it) {
Delta *del = it.value();
if (Version(del->versionFrom()) == version)
return del;
}
......
......@@ -122,9 +122,12 @@ void RunnerWorker::processNextPhase()
break;
case Operation::Phase5:
//Now we need to move all ops back to the main app thread
foreach (QList<Operation*> ops, m_operations.values()) {
foreach (Operation * op, ops)
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it) {
const auto ops = it.value();
for ( auto it2 = ops.constBegin(), end2 = ops.constEnd(); it2 != end2; ++it2 ) {
Operation* op = *it2;
op->moveToThread(QCoreApplication::instance()->thread());
}
}
// If we're here, we're successfully over.
emit runFinished(true);
......@@ -234,10 +237,15 @@ void RunnerRunnable::run()
//Don't parent, otherwise we break thread-affinity!!!
m_worker = new RunnerWorker(m_operations);
m_worker->moveToThread(m_thread);
foreach (QList<Operation*> ops, m_operations.values()) {
foreach (Operation * op, ops)
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it) {
const auto ops = it.value();
for ( auto it2 = ops.constBegin(), end2 = ops.constEnd(); it2 != end2; ++it2 ) {
Operation* op = *it2;
op->moveToThread(m_thread);
}
}
emit ready();
QTimer::singleShot(0, m_worker, SLOT(run()));
m_thread->start();
......
......@@ -142,10 +142,12 @@ void ValidatorWorker::processNextPhase()
break;
case Operation::Phase5:
//Now we need to move all ops back to the main app thread
foreach (QList<Operation*> ops, m_operations.values()) {
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it ) {
const auto ops = it.value();
foreach (Operation * op, ops)
op->moveToThread(QCoreApplication::instance()->thread());
}
// If we're here, we're successfully over.
emit validationFinished(true, m_operations);
return;
......@@ -467,7 +469,8 @@ void ValidatorRunnable::run()
//Don't use a parent here, otherwise we break thread affinity!!!
m_worker = new ValidatorWorker(m_operations);
m_worker->moveToThread(m_thread);
foreach (QList<Operation*> ops, m_operations.values()) {
for (auto it = m_operations.constBegin(), end = m_operations.constEnd(); it != end; ++it ) {
const auto ops = it.value();
foreach (Operation * op, ops)
op->moveToThread(m_thread);
}
......
......@@ -193,11 +193,10 @@ size_t ArchiveHandler::getEntrySize(QString const& fileName) const
size_t ArchiveHandler::totalEntrySize() const
{
size_t total = 0;
foreach (const QString& file, entries.keys()) {
for (auto it = entries.constBegin(), end = entries.constEnd(); it != end; ++it) {
const auto& file = it.key();
total += entries[file]->getFileSize();
}
return total;
}
......
......@@ -86,8 +86,10 @@ bool PolKitArchiveHandler::write(const QString& filename, const QHash<QString, Q
iface.setProperty("filename", filename);
QVariantMap map;
foreach (const QString &k, files.keys())
for (auto it = files.constBegin(), end = files.constEnd(); it != end; ++it) {
const auto& k = it.key();
map.insert(k, files[k]);
}
QDBusMessage mes = iface.call("write", map);
return !mes.arguments().isEmpty() && mes.arguments().first().toBool();
} else {
......
......@@ -78,7 +78,8 @@ void PolkitReInstallOperation::run()
QStringList files = d->localPackage->retrieveFiles();
QMap<QString, QString> backup = d->package->backupFiles();
foreach (const QString &b, backup.keys()) {
for (auto it = backup.constBegin(), end = backup.constEnd(); it != end; ++it) {
const auto& b = it.key();
if (b.isEmpty() || backup[b].isEmpty())
continue;
files.removeAll(b);
......
......@@ -60,9 +60,9 @@ void PolkitRemoveOperation::run()
// Remove all files
if (!(processingOptions().testFlag(Akabei::DatabaseOnly))) {
QStringList files = d->package->retrieveFiles();
QMap<QString, QString> backup = d->package->backupFiles();
foreach (const QString &b, backup.keys()) {
QMap<QString, QString> backup = d->package->backupFiles();
for (auto it = backup.constBegin(), end = backup.constEnd(); it != end; ++it) {
const auto& b = it.key();
if (processingOptions().testFlag(Akabei::RemoveConfigs) || b.isEmpty() || backup[b].isEmpty())
continue;
files.removeAll(b);
......
......@@ -99,7 +99,8 @@ void PolkitReplaceOperation::run()
Package * replacedpkg = d->replaces[i];
QMap<QString, QString> backup = replacedpkg->backupFiles();
foreach (const QString &b, backup.keys()) {
for (auto it = backup.constBegin(), end = backup.constEnd(); it != end; ++it ) {
const auto& b = it.key();
if (b.isEmpty() || backup[b].isEmpty())
continue;
files.removeAll(b);
......
......@@ -83,7 +83,8 @@ void PolkitUpgradeOperation::run()
QStringList files = d->from->retrieveFiles();
QMap<QString, QString> backup = d->to->backupFiles();
foreach (const QString &b, backup.keys()) {
for (auto it = backup.constBegin(), end = backup.constEnd(); it != end; ++it) {
const auto& b = it.key();
if (b.isEmpty() || backup[b].isEmpty())
continue;
files.removeAll(b);
......
......@@ -360,7 +360,8 @@ bool DatabaseWorker::add(const QStringList& targets, const QHash< QString, Akabe
}
QList<Akabei::Hook*> realHooks;
foreach (const QString &h, hookPaths.keys()) {
for (auto it = hookPaths.constBegin(), end = hookPaths.constEnd(); it != end; ++it) {
const auto& h = it.key();
Akabei::Hook * hook = Akabei::Backend::instance()->loadHookFromFile(hookPaths[h], hooks[h]);
if (hook) {
realHooks << hook;
......
......@@ -266,7 +266,8 @@ bool ArchiveHandlerHelper::write(const QVariantMap& files)
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
qDebug() << "Auth gained to do the task";
QHash<QString, QString> hash; //FIXME: Optimize, aka make a method in archivehandler to take a qvariantmap
foreach (QString key, files.keys()) {
for (auto it = files.constBegin(), end = files.constEnd(); it != end; ++it ) {
auto key = it.key();
hash.insert(key, files[key].toString());
}
return ArchiveHandler::write(m_filename, hash);
......
......@@ -103,7 +103,8 @@ void SQLiteHelper::query(const QString &query, const QVariantMap &bindings)
if (auth == PolkitQt1::Authority::Yes && CHECK_PID) {
try {
QVariantMap result;
foreach (const QString &k, bindings.keys()) {
for (auto it = bindings.constBegin(), end = bindings.constEnd(); it != end; ++it ) {
const auto& k = it.key();
QDBusArgument arg = bindings.value(k).value<QDBusArgument>();
QList<QVariant> entries;
arg >> entries;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment