diff --git a/src/plugins/valgrind/callgrind/callgrindcycledetection.cpp b/src/plugins/valgrind/callgrind/callgrindcycledetection.cpp index b47ecb4697d..79443aa5b65 100644 --- a/src/plugins/valgrind/callgrind/callgrindcycledetection.cpp +++ b/src/plugins/valgrind/callgrind/callgrindcycledetection.cpp @@ -45,14 +45,14 @@ CycleDetection::CycleDetection(ParseData *data) QVector CycleDetection::run(const QVector &input) { - foreach (const Function *function, input) { + for (const Function *function : input) { Node *node = new Node; node->function = function; node->dfs = -1; node->lowlink = -1; m_nodes.insert(function, node); } - foreach (Node *node, m_nodes) { + for (Node *node : qAsConst(m_nodes)) { if (node->dfs == -1) tarjan(node); } @@ -69,7 +69,8 @@ void CycleDetection::tarjan(Node *node) m_depth++; m_stack.push(node); - foreach (const FunctionCall *call, node->function->outgoingCalls()) + const QVector calls = node->function->outgoingCalls(); + for (const FunctionCall *call : calls) tarjanForChildNode(node, m_nodes.value(call->callee())); if (node->dfs == node->lowlink) { diff --git a/src/plugins/valgrind/callgrind/callgrindfunction.cpp b/src/plugins/valgrind/callgrind/callgrindfunction.cpp index f468164aec3..9a7f4fe81bc 100644 --- a/src/plugins/valgrind/callgrind/callgrindfunction.cpp +++ b/src/plugins/valgrind/callgrind/callgrindfunction.cpp @@ -67,7 +67,7 @@ void Function::Private::accumulateCost(QVector &base, const QVectorm_costItems) { + for (const CostItem *costItem : qAsConst(d->m_costItems)) { if (costItem->differingFileId() != -1) { QTextStream stream(&pos); stream << '('; @@ -214,7 +214,7 @@ int Function::lineNumber() const if (lineIdx == -1) return -1; - foreach (const CostItem *costItem, d->m_costItems) { + for (const CostItem *costItem : qAsConst(d->m_costItems)) { if (costItem->differingFileId() == -1) return costItem->position(lineIdx); } @@ -287,7 +287,7 @@ void Function::addCostItem(const CostItem *item) void Function::finalize() { bool recursive = false; - foreach (const FunctionCall *call, d->m_incomingCalls) { + for (const FunctionCall *call : qAsConst(d->m_incomingCalls)) { if (call->caller() == this) { recursive = true; break; @@ -300,9 +300,10 @@ void Function::finalize() // e.g.: A -> B -> B ..., C -> B -> B ... // cost of B = cost of call to B in A + cost of call to B in C + ... d->m_inclusiveCost.fill(0); - foreach (const FunctionCall *call, d->m_incomingCalls) { + for (const FunctionCall *call : qAsConst(d->m_incomingCalls)) { if (call->caller() != this) { - foreach (const CostItem *costItem, call->caller()->costItems()) { + const QVector costItems = call->caller()->costItems(); + for (const CostItem *costItem : costItems) { if (costItem->call() && costItem->call()->callee() == this) d->accumulateCost(d->m_inclusiveCost, costItem->costs()); } diff --git a/src/plugins/valgrind/callgrind/callgrindfunctioncycle.cpp b/src/plugins/valgrind/callgrind/callgrindfunctioncycle.cpp index e070b5a6876..c9c43cb3021 100644 --- a/src/plugins/valgrind/callgrind/callgrindfunctioncycle.cpp +++ b/src/plugins/valgrind/callgrind/callgrindfunctioncycle.cpp @@ -73,16 +73,17 @@ void FunctionCycle::setFunctions(const QVector &functions) d->m_selfCost.fill(0, d->m_data->events().size()); d->m_inclusiveCost.fill(0, d->m_data->events().size()); - foreach (const Function *func, functions) { + for (const Function *func : functions) { // just add up self cost Private::accumulateCost(d->m_selfCost, func->selfCosts()); // add outgoing calls to functions that are not part of the cycle - foreach (const FunctionCall *call, func->outgoingCalls()) { + const QVector calls = func->outgoingCalls(); + for (const FunctionCall *call : calls) { if (!functions.contains(call->callee())) d->accumulateCall(call, Function::Private::Outgoing); } // add incoming calls from functions that are not part of the cycle - foreach (const FunctionCall *call, func->incomingCalls()) { + for (const FunctionCall *call : calls) { if (!functions.contains(call->caller())) { d->accumulateCall(call, Function::Private::Incoming); d->m_called += call->calls(); diff --git a/src/plugins/valgrind/callgrind/callgrindparsedata.cpp b/src/plugins/valgrind/callgrind/callgrindparsedata.cpp index 55398ce79ae..ba1e4258023 100644 --- a/src/plugins/valgrind/callgrind/callgrindparsedata.cpp +++ b/src/plugins/valgrind/callgrind/callgrindparsedata.cpp @@ -92,7 +92,7 @@ ParseData::Private::~Private() void ParseData::Private::cleanupFunctionCycles() { m_cycleCacheValid = false; - foreach (const Function *func, m_cycleCache) { + for (const Function *func : qAsConst(m_cycleCache)) { if (dynamic_cast(func)) delete func; } diff --git a/src/plugins/valgrind/callgrind/callgrindparser.cpp b/src/plugins/valgrind/callgrind/callgrindparser.cpp index 1288bd16846..421583d3671 100644 --- a/src/plugins/valgrind/callgrind/callgrindparser.cpp +++ b/src/plugins/valgrind/callgrind/callgrindparser.cpp @@ -219,17 +219,19 @@ void Parser::Private::parse(const FilePath &filePath) // build fast lookup of functions by their nameId QHash > functionLookup; - foreach (const Function *function, data->functions()) { + const QVector functions = data->functions(); + for (const Function *function : functions) { functionLookup[function->nameId()].append(function); } // functions that need to accumulate their calees QSet pendingFunctions; - foreach (const CallData &callData, pendingCallees) { + for (const CallData &callData : qAsConst(pendingCallees)) { Function *calledFunction = nullptr; QTC_ASSERT(callData.call, continue); QTC_ASSERT(callData.call->caller(), continue); - foreach (const Function *function, functionLookup.value(callData.calledFunction)) { + const QList functions = functionLookup.value(callData.calledFunction); + for (const Function *function : functions) { QTC_ASSERT(function->nameId() == callData.calledFunction, continue); if (function->objectId() == callData.calledObject && function->fileId() == callData.calledFile) @@ -245,7 +247,7 @@ void Parser::Private::parse(const FilePath &filePath) qDebug() << "caller is:" << callData.call->caller()->name() << callData.call->caller()->nameId(); qDebug() << "called file:" << callData.calledFile << "object:" << callData.calledObject; qDebug() << data->stringForFileCompression(callData.calledFile) << data->stringForObjectCompression(callData.calledObject); - foreach (const Function *function, functionLookup.value(callData.calledFunction)) { + for (const Function *function, functionLookup.value(callData.calledFunction)) { qDebug() << "available function file:" << function->fileId() << function->file() << "object:" << function->objectId() << function->object(); } } @@ -263,7 +265,7 @@ void Parser::Private::parse(const FilePath &filePath) // lookup done // now accumulate callees - foreach (Function *func, pendingFunctions) + for (Function *func : qAsConst(pendingFunctions)) func->finalize(); emit q->parserDataReady(); @@ -322,7 +324,8 @@ void Parser::Private::parseHeader(QIODevice *device) } else if (line.startsWith("summary: ")) { QString values = getValue(line, 9); uint i = 0; - foreach (const QString &value, values.split(' ', Qt::SkipEmptyParts)) + const QStringList valueList = values.split(' ', Qt::SkipEmptyParts); + for (const QString &value : valueList) data->setTotalCost(i++, value.toULongLong()); } else if (!line.trimmed().isEmpty()) { // handle line and exit parseHeader diff --git a/src/plugins/valgrind/callgrind/callgrindproxymodel.cpp b/src/plugins/valgrind/callgrind/callgrindproxymodel.cpp index 66a362f4956..68f77e83f88 100644 --- a/src/plugins/valgrind/callgrind/callgrindproxymodel.cpp +++ b/src/plugins/valgrind/callgrind/callgrindproxymodel.cpp @@ -130,7 +130,8 @@ bool DataProxyModel::filterAcceptsRow(int source_row, const QModelIndex &source_ // check if the function from this index is a child of (called by) the filter function if (m_function) { bool isValid = false; - foreach (const FunctionCall *call, func->incomingCalls()) { + const QVector calls = func->incomingCalls(); + for (const FunctionCall *call : calls) { if (call->caller() == m_function) { isValid = true; break; diff --git a/src/plugins/valgrind/callgrindtool.cpp b/src/plugins/valgrind/callgrindtool.cpp index a44beb02243..f5cef8600de 100644 --- a/src/plugins/valgrind/callgrindtool.cpp +++ b/src/plugins/valgrind/callgrindtool.cpp @@ -735,7 +735,8 @@ void CallgrindToolPrivate::updateEventCombo() } m_eventCombo->show(); - foreach (const QString &event, data->events()) + const QStringList events = data->events(); + for (const QString &event : events) m_eventCombo->addItem(ParseData::prettyStringForEvent(event)); } @@ -848,7 +849,7 @@ void CallgrindToolPrivate::editorOpened(IEditor *editor) void CallgrindToolPrivate::requestContextMenu(TextEditorWidget *widget, int line, QMenu *menu) { // Find callgrind text mark that corresponds to this editor's file and line number - foreach (CallgrindTextMark *textMark, m_textMarks) { + for (CallgrindTextMark *textMark : qAsConst(m_textMarks)) { if (textMark->fileName() == widget->textDocument()->filePath() && textMark->lineNumber() == line) { const Function *func = textMark->function(); QAction *action = menu->addAction(CallgrindTool::tr("Select This Function in the Analyzer Output")); diff --git a/src/plugins/valgrind/callgrindvisualisation.cpp b/src/plugins/valgrind/callgrindvisualisation.cpp index 4d829394c5d..e159b153b3b 100644 --- a/src/plugins/valgrind/callgrindvisualisation.cpp +++ b/src/plugins/valgrind/callgrindvisualisation.cpp @@ -236,7 +236,8 @@ void Visualization::Private::handleMousePressEvent(QMouseEvent *event, { // find the first item that accepts mouse presses under the cursor position QGraphicsItem *itemAtPos = nullptr; - foreach (QGraphicsItem *item, q->items(event->pos())) { + const QListitems = q->items(event->pos()); + for (QGraphicsItem *item : items) { if (!(item->acceptedMouseButtons() & event->button())) continue; @@ -291,7 +292,8 @@ const Function *Visualization::functionForItem(QGraphicsItem *item) const QGraphicsItem *Visualization::itemForFunction(const Function *function) const { - foreach (QGraphicsItem *item, items()) { + const QList itemList = items(); + for (QGraphicsItem *item : itemList) { if (functionForItem(item) == function) return item; } diff --git a/src/plugins/valgrind/memcheckerrorview.cpp b/src/plugins/valgrind/memcheckerrorview.cpp index 19e3199b72b..951136f8c6e 100644 --- a/src/plugins/valgrind/memcheckerrorview.cpp +++ b/src/plugins/valgrind/memcheckerrorview.cpp @@ -100,7 +100,7 @@ QList MemcheckErrorView::customActions() const QTC_ASSERT(!indizes.isEmpty(), return actions); bool hasErrors = false; - foreach (const QModelIndex &index, indizes) { + for (const QModelIndex &index : indizes) { Error error = model()->data(index, ErrorListModel::ErrorRole).value(); if (!error.suppression().isNull()) { hasErrors = true; diff --git a/src/plugins/valgrind/memchecktool.cpp b/src/plugins/valgrind/memchecktool.cpp index 1e093b354a4..99cbf51d72e 100644 --- a/src/plugins/valgrind/memchecktool.cpp +++ b/src/plugins/valgrind/memchecktool.cpp @@ -284,7 +284,7 @@ static ErrorListModel::RelevantFrameFinder makeFrameFinder(const QStringList &pr //find the first frame belonging to the project if (!projectFiles.isEmpty()) { - foreach (const Frame &frame, frames) { + for (const Frame &frame : frames) { if (frame.directory().isEmpty() || frame.fileName().isEmpty()) continue; @@ -296,7 +296,7 @@ static ErrorListModel::RelevantFrameFinder makeFrameFinder(const QStringList &pr } //if no frame belonging to the project was found, return the first one that is not malloc/new - foreach (const Frame &frame, frames) { + for (const Frame &frame : frames) { if (!frame.functionName().isEmpty() && frame.functionName() != "malloc" && !frame.functionName().startsWith("operator new(")) { @@ -365,9 +365,10 @@ bool MemcheckErrorFilterProxyModel::filterAcceptsRow(int sourceRow, const QModel QSet validFolders; for (Project *project : SessionManager::projects()) { validFolders << project->projectDirectory().toString(); - foreach (Target *target, project->targets()) { - foreach (const DeployableFile &file, - target->deploymentData().allFiles()) { + const QList targets = project->targets(); + for (const Target *target : targets) { + const QList files = target->deploymentData().allFiles(); + for (const DeployableFile &file : files) { if (file.isExecutable()) validFolders << file.remoteDirectory(); } @@ -383,7 +384,7 @@ bool MemcheckErrorFilterProxyModel::filterAcceptsRow(int sourceRow, const QModel bool inProject = false; for (int i = 0; i < framesToLookAt; ++i) { const Frame &frame = frames.at(i); - foreach (const QString &folder, validFolders) { + for (const QString &folder : qAsConst(validFolders)) { if (frame.directory().startsWith(folder)) { inProject = true; break; @@ -633,7 +634,7 @@ MemcheckToolPrivate::MemcheckToolPrivate() filterButton->setProperty("noArrow", true); m_filterMenu = new QMenu(filterButton); - foreach (QAction *filterAction, m_errorFilterActions) + for (QAction *filterAction : qAsConst(m_errorFilterActions)) m_filterMenu->addAction(filterAction); m_filterMenu->addSeparator(); m_filterMenu->addAction(m_filterProjectAction); @@ -934,9 +935,10 @@ void MemcheckToolPrivate::settingsDestroyed(QObject *settings) void MemcheckToolPrivate::updateFromSettings() { - foreach (QAction *action, m_errorFilterActions) { + for (QAction *action : qAsConst(m_errorFilterActions)) { bool contained = true; - foreach (const QVariant &v, action->data().toList()) { + const QList actions = action->data().toList(); + for (const QVariant &v : actions) { bool ok; int kind = v.toInt(&ok); if (ok && !m_settings->visibleErrorKinds.value().contains(kind)) @@ -1119,10 +1121,11 @@ void MemcheckToolPrivate::updateErrorFilter() m_settings->filterExternalIssues.setValue(!m_filterProjectAction->isChecked()); QList errorKinds; - foreach (QAction *a, m_errorFilterActions) { + for (QAction *a : qAsConst(m_errorFilterActions)) { if (!a->isChecked()) continue; - foreach (const QVariant &v, a->data().toList()) { + const QList actions = a->data().toList(); + for (const QVariant &v : actions) { bool ok; int kind = v.toInt(&ok); if (ok) diff --git a/src/plugins/valgrind/xmlprotocol/error.cpp b/src/plugins/valgrind/xmlprotocol/error.cpp index efc04f52232..0adf0dbfab8 100644 --- a/src/plugins/valgrind/xmlprotocol/error.cpp +++ b/src/plugins/valgrind/xmlprotocol/error.cpp @@ -205,12 +205,13 @@ QString Error::toXml() const stream << " " << d->what << "\n"; } - foreach (const Stack &stack, d->stacks) { + for (const Stack &stack : qAsConst(d->stacks)) { if (!stack.auxWhat().isEmpty()) stream << " " << stack.auxWhat() << "\n"; stream << " \n"; - foreach (const Frame &frame, stack.frames()) { + const QVector frames = stack.frames(); + for (const Frame &frame : frames) { stream << " \n"; stream << " 0x" << QString::number(frame.instructionPointer(), 16) << "\n"; if (!frame.object().isEmpty()) diff --git a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp index a4d4234d070..7431b0692cd 100644 --- a/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp +++ b/src/plugins/valgrind/xmlprotocol/errorlistmodel.cpp @@ -165,10 +165,12 @@ ErrorItem::ErrorItem(const ErrorListModel *model, const Error &error) // just annoy the user. // The same goes for the frame level. if (m_error.stacks().count() > 1) { - foreach (const Stack &s, m_error.stacks()) + const QVector stacks = m_error.stacks(); + for (const Stack &s : stacks) appendChild(new StackItem(s)); } else if (m_error.stacks().constFirst().frames().count() > 1) { - foreach (const Frame &f, m_error.stacks().constFirst().frames()) + const QVector frames = m_error.stacks().constFirst().frames(); + for (const Frame &f : frames) appendChild(new FrameItem(f)); } } @@ -197,11 +199,13 @@ QVariant ErrorItem::data(int column, int role) const << m_model->errorLocation(m_error) << "\n"; - foreach (const Stack &stack, m_error.stacks()) { + const QVector stacks = m_error.stacks(); + for (const Stack &stack : stacks) { if (!stack.auxWhat().isEmpty()) stream << stack.auxWhat(); int i = 1; - foreach (const Frame &frame, stack.frames()) + const QVector frames = stack.frames(); + for (const Frame &frame : frames) stream << " " << i++ << ": " << makeFrameName(frame, true) << "\n"; } @@ -229,7 +233,8 @@ QVariant ErrorItem::data(int column, int role) const StackItem::StackItem(const Stack &stack) : m_stack(stack) { - foreach (const Frame &f, m_stack.frames()) + const QVector frames = m_stack.frames(); + for (const Frame &f : frames) appendChild(new FrameItem(f)); } diff --git a/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp b/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp index 48e0a325771..d2722311871 100644 --- a/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp +++ b/src/plugins/valgrind/xmlprotocol/modelhelpers.cpp @@ -64,7 +64,7 @@ QString toolTipForFrame(const Frame &frame) "\n" "
"; - foreach (const StringPair &pair, lines) { + for (const StringPair &pair : qAsConst(lines)) { html += "
"; html += pair.first; html += "
"; diff --git a/src/plugins/valgrind/xmlprotocol/suppression.cpp b/src/plugins/valgrind/xmlprotocol/suppression.cpp index 14ad429416f..0864a2f2f4e 100644 --- a/src/plugins/valgrind/xmlprotocol/suppression.cpp +++ b/src/plugins/valgrind/xmlprotocol/suppression.cpp @@ -208,7 +208,7 @@ QString Suppression::toString() const stream << "{\n"; stream << indent << d->name << '\n'; stream << indent << d->kind << '\n'; - foreach (const SuppressionFrame &frame, d->frames) + for (const SuppressionFrame &frame : qAsConst(d->frames)) stream << indent << frame.toString() << '\n'; stream << "}\n"; return ret;