Commit 7d38f5e5 authored by Friedrich W. H. Kossebau's avatar Friedrich W. H. Kossebau
Browse files

kdevplastform/language/backgroundparser: port foreach -> range-based for

parent 93c537e8
......@@ -574,7 +574,8 @@ void BackgroundParser::revertAllRequests(QObject* notifyWhenReady)
for (auto it = d->m_documents.begin(); it != d->m_documents.end();) {
d->m_documentsForPriority[it.value().priority()].remove(it.key());
foreach (const DocumentParseTarget& target, (*it).targets) {
const auto oldTargets = (*it).targets;
for (const DocumentParseTarget& target : oldTargets) {
if (notifyWhenReady && target.notifyWhenReady.data() == notifyWhenReady) {
(*it).targets.remove(target);
}
......@@ -638,7 +639,8 @@ void BackgroundParser::removeDocument(const IndexedString& url, QObject* notifyW
auto& documentParsePlan = *documentParsePlanIt;
d->m_documentsForPriority[documentParsePlan.priority()].remove(url);
foreach (const DocumentParseTarget& target, documentParsePlan.targets) {
const auto oldTargets = documentParsePlan.targets;
for (const DocumentParseTarget& target : oldTargets) {
if (target.notifyWhenReady.data() == notifyWhenReady) {
documentParsePlan.targets.remove(target);
}
......
......@@ -107,8 +107,7 @@ ParseJob::ParseJob(const IndexedString& url, KDevelop::ILanguageSupport* languag
ParseJob::~ParseJob()
{
using QObjectPointer = QPointer<QObject>;
foreach (const QObjectPointer& p, d->notify) {
for (auto& p : qAsConst(d->notify)) {
if (p) {
QMetaObject::invokeMethod(p.data(), "updateReady", Qt::QueuedConnection,
Q_ARG(KDevelop::IndexedString, d->url),
......@@ -477,7 +476,8 @@ bool ParseJob::isUpdateRequired(const IndexedString& languageString)
if (abortRequested()) {
return false;
}
foreach (const ParsingEnvironmentFilePointer& file, DUChain::self()->allEnvironmentFiles(document())) {
const auto files = DUChain::self()->allEnvironmentFiles(document());
for (const ParsingEnvironmentFilePointer& file : files) {
if (file->language() != languageString) {
continue;
}
......
......@@ -79,7 +79,8 @@ ParseProjectJob::ParseProjectJob(IProject* project, bool forceUpdate, bool force
d->filesToParse = project->fileSet();
} else {
// In case we don't want to parse the whole project, still add all currently open files that belong to the project to the background-parser
foreach (auto document, ICore::self()->documentController()->openDocuments()) {
const auto documents = ICore::self()->documentController()->openDocuments();
for (auto* document : documents) {
const auto path = IndexedString(document->url());
if (project->fileSet().contains(path)) {
d->filesToParse.insert(path);
......@@ -151,7 +152,8 @@ void ParseProjectJob::start()
}
// Add all currently open files that belong to the project to the background-parser, so that they'll be parsed first of all
foreach (auto document, ICore::self()->documentController()->openDocuments()) {
const auto documents = ICore::self()->documentController()->openDocuments();
for (auto* document : documents) {
const auto path = IndexedString(document->url());
auto fileIt = d->filesToParse.find(path);
if (fileIt != d->filesToParse.end()) {
......@@ -172,7 +174,7 @@ void ParseProjectJob::start()
int processed = 0;
// guard against reentrancy issues, see also bug 345480
auto crashGuard = QPointer<ParseProjectJob> {this};
foreach (const IndexedString& url, d->filesToParse) {
for (const IndexedString& url : qAsConst(d->filesToParse)) {
ICore::self()->languageController()->backgroundParser()->addDocument(url, processingLevel,
BackgroundParser::InitialParsePriority,
this);
......
......@@ -87,7 +87,7 @@ void JobPlan::parseJobCreated(ParseJob* job)
void JobPlan::addJobsToParser()
{
// add parse jobs
foreach (const JobPrototype& job, m_jobs) {
for (const JobPrototype& job : qAsConst(m_jobs)) {
ICore::self()->languageController()->backgroundParser()->addDocument(
job.m_url, TopDUContext::Empty, job.m_priority, this, job.m_flags
);
......@@ -113,7 +113,7 @@ bool JobPlan::runJobs(int timeoutMS)
// verify they're started in the right order
int currentBestPriority = BackgroundParser::BestPriority;
foreach (const IndexedString& url, m_createdJobs) {
for (const IndexedString& url : qAsConst(m_createdJobs)) {
const JobPrototype p = jobForUrl(url);
QVERIFY_RETURN(p.m_priority >= currentBestPriority, false);
currentBestPriority = p.m_priority;
......@@ -122,15 +122,13 @@ bool JobPlan::runJobs(int timeoutMS)
return true;
}
JobPrototype JobPlan::jobForUrl(const IndexedString& url)
JobPrototype JobPlan::jobForUrl(const IndexedString& url) const
{
foreach (const JobPrototype& job, m_jobs) {
if (job.m_url == url) {
return job;
}
}
auto it = std::find_if(m_jobs.begin(), m_jobs.end(), [&](const JobPrototype& job) {
return (job.m_url == url);
});
return JobPrototype();
return (it != m_jobs.end()) ? *it: JobPrototype();
}
void JobPlan::updateReady(const IndexedString& url, const ReferencedTopDUContext& /*context*/)
......@@ -148,7 +146,7 @@ void JobPlan::updateReady(const IndexedString& url, const ReferencedTopDUContext
if (job.m_flags & ParseJob::RequiresSequentialProcessing) {
// ensure that all jobs that respect sequential processing
// with lower priority have been run
foreach (const JobPrototype& otherJob, m_jobs) {
for (const JobPrototype& otherJob : qAsConst(m_jobs)) {
if (otherJob.m_url == job.m_url) {
continue;
}
......@@ -319,7 +317,7 @@ void TestBackgroundparser::benchmark()
}
QBENCHMARK {
foreach (const IndexedString& url, jobUrls) {
for (const IndexedString& url : qAsConst(jobUrls)) {
ICore::self()->languageController()->backgroundParser()->addDocument(url);
}
......
......@@ -74,7 +74,7 @@ public:
void clear();
JobPrototype jobForUrl(const IndexedString& url);
JobPrototype jobForUrl(const IndexedString& url) const;
int numJobs() const;
int numFinishedJobs() const;
......
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