Skip to content

Commit 564bc71

Browse files
committed
Don't use foreach, prefer range-based-for loops
1 parent d8fcddd commit 564bc71

File tree

5 files changed

+15
-8
lines changed

5 files changed

+15
-8
lines changed

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ file(RELATIVE_PATH LIBEXEC_REL_PATH "${KDE_INSTALL_FULL_BINDIR}" "${KDE_INSTALL_
150150

151151
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/hotspot-config.h.cmake ${CMAKE_CURRENT_BINARY_DIR}/hotspot-config.h @ONLY)
152152

153-
add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_USE_QSTRINGBUILDER)
153+
add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_USE_QSTRINGBUILDER -DQT_NO_FOREACH)
154154
add_compile_options(-Wall -pedantic -Wextra)
155155
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
156156
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)

src/flamegraph.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -471,7 +471,7 @@ void layoutItems(FrameGraphicsItem* parent)
471471
< static_cast<const FrameGraphicsItem*>(rhs)->symbol();
472472
});
473473

474-
foreach (auto child, children) {
474+
for (auto child : children) {
475475
auto frameChild = static_cast<FrameGraphicsItem*>(child);
476476
const qreal w = maxWidth * double(frameChild->cost()) / parent->cost();
477477
frameChild->setVisible(w > 1);
@@ -485,7 +485,7 @@ void layoutItems(FrameGraphicsItem* parent)
485485

486486
FrameGraphicsItem* findItemBySymbol(const QList<QGraphicsItem*>& items, const Data::Symbol& symbol)
487487
{
488-
foreach (auto item_, items) {
488+
for (auto item_ : items) {
489489
auto item = static_cast<FrameGraphicsItem*>(item_);
490490
if (item->symbol() == symbol) {
491491
return item;
@@ -501,7 +501,7 @@ template<typename Tree>
501501
void toGraphicsItems(const Data::Costs& costs, int type, const QVector<Tree>& data, FrameGraphicsItem* parent,
502502
const double costThreshold, const BrushConfig& brushConfig, bool collapseRecursion)
503503
{
504-
foreach (const auto& row, data) {
504+
for (const auto& row : data) {
505505
if (collapseRecursion && !row.symbol.symbol.isEmpty() && row.symbol == parent->symbol()) {
506506
if (costs.cost(type, row.id) > costThreshold) {
507507
toGraphicsItems(costs, type, row.children, parent, costThreshold, brushConfig, collapseRecursion);
@@ -1178,7 +1178,8 @@ void FlameGraph::selectItem(FrameGraphicsItem* item)
11781178
rect.setWidth(rootWidth);
11791179
parent->setRect(rect);
11801180
if (parent->parentItem()) {
1181-
foreach (auto sibling, parent->parentItem()->childItems()) {
1181+
const auto children = parent->parentItem()->childItems();
1182+
for (auto sibling : children) {
11821183
sibling->setVisible(sibling == parent);
11831184
}
11841185
}

src/frequencypage.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,16 @@
66
SPDX-License-Identifier: GPL-2.0-or-later
77
*/
88

9+
// NOTE: QCustomPlot still uses foreach
10+
#undef QT_NO_FOREACH
11+
#include <qcustomplot.h>
12+
#undef foreach
13+
#define QT_NO_FOREACH
14+
915
#include "frequencypage.h"
1016

1117
#include <KColorScheme>
1218
#include <QDebug>
13-
#include <qcustomplot.h>
1419

1520
#include "parsers/perf/perfparser.h"
1621
#include "ui_frequencypage.h"

src/models/processlist_unix.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ ProcDataList processList()
104104
return unixProcessListPS();
105105

106106
ProcDataList rc;
107-
foreach (const QString& procId, procDir.entryList()) {
107+
const auto entries = procDir.entryList();
108+
for (const QString& procId : entries) {
108109
if (!isUnixProcessId(procId))
109110
continue;
110111

src/models/processmodel.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ void ProcessModel::mergeProcesses(const ProcDataList& processes)
3737
// iterator over m_data
3838
int i = 0;
3939

40-
foreach (const ProcData& newProc, sortedProcesses) {
40+
for (const ProcData& newProc : sortedProcesses) {
4141
bool shouldInsert = true;
4242
while (i < m_data.count()) {
4343
const ProcData& oldProc = m_data.at(i);

0 commit comments

Comments
 (0)