Skip to content

Commit

Permalink
Don't use foreach, prefer range-based-for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
milianw committed Oct 22, 2024
1 parent d8fcddd commit 564bc71
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 8 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ file(RELATIVE_PATH LIBEXEC_REL_PATH "${KDE_INSTALL_FULL_BINDIR}" "${KDE_INSTALL_

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

add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_USE_QSTRINGBUILDER)
add_definitions(-DQT_NO_CAST_FROM_ASCII -DQT_NO_CAST_TO_ASCII -DQT_USE_QSTRINGBUILDER -DQT_NO_FOREACH)
add_compile_options(-Wall -pedantic -Wextra)
if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-gnu-zero-variadic-macro-arguments)
Expand Down
9 changes: 5 additions & 4 deletions src/flamegraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ void layoutItems(FrameGraphicsItem* parent)
< static_cast<const FrameGraphicsItem*>(rhs)->symbol();
});

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

FrameGraphicsItem* findItemBySymbol(const QList<QGraphicsItem*>& items, const Data::Symbol& symbol)
{
foreach (auto item_, items) {
for (auto item_ : items) {
auto item = static_cast<FrameGraphicsItem*>(item_);
if (item->symbol() == symbol) {
return item;
Expand All @@ -501,7 +501,7 @@ template<typename Tree>
void toGraphicsItems(const Data::Costs& costs, int type, const QVector<Tree>& data, FrameGraphicsItem* parent,
const double costThreshold, const BrushConfig& brushConfig, bool collapseRecursion)
{
foreach (const auto& row, data) {
for (const auto& row : data) {
if (collapseRecursion && !row.symbol.symbol.isEmpty() && row.symbol == parent->symbol()) {
if (costs.cost(type, row.id) > costThreshold) {
toGraphicsItems(costs, type, row.children, parent, costThreshold, brushConfig, collapseRecursion);
Expand Down Expand Up @@ -1178,7 +1178,8 @@ void FlameGraph::selectItem(FrameGraphicsItem* item)
rect.setWidth(rootWidth);
parent->setRect(rect);
if (parent->parentItem()) {
foreach (auto sibling, parent->parentItem()->childItems()) {
const auto children = parent->parentItem()->childItems();
for (auto sibling : children) {
sibling->setVisible(sibling == parent);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/frequencypage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@
SPDX-License-Identifier: GPL-2.0-or-later
*/

// NOTE: QCustomPlot still uses foreach
#undef QT_NO_FOREACH
#include <qcustomplot.h>
#undef foreach
#define QT_NO_FOREACH

#include "frequencypage.h"

#include <KColorScheme>
#include <QDebug>
#include <qcustomplot.h>

#include "parsers/perf/perfparser.h"
#include "ui_frequencypage.h"
Expand Down
3 changes: 2 additions & 1 deletion src/models/processlist_unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,8 @@ ProcDataList processList()
return unixProcessListPS();

ProcDataList rc;
foreach (const QString& procId, procDir.entryList()) {
const auto entries = procDir.entryList();
for (const QString& procId : entries) {
if (!isUnixProcessId(procId))
continue;

Expand Down
2 changes: 1 addition & 1 deletion src/models/processmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void ProcessModel::mergeProcesses(const ProcDataList& processes)
// iterator over m_data
int i = 0;

foreach (const ProcData& newProc, sortedProcesses) {
for (const ProcData& newProc : sortedProcesses) {
bool shouldInsert = true;
while (i < m_data.count()) {
const ProcData& oldProc = m_data.at(i);
Expand Down

0 comments on commit 564bc71

Please sign in to comment.