Fix Clazy range-loop-detach warnings

This commit is contained in:
Cameron Gutman
2026-01-26 21:00:07 -06:00
parent f5f06ae44e
commit d484ec3ac8
14 changed files with 42 additions and 35 deletions

View File

@@ -1,5 +1,5 @@
QT += core quick network quickcontrols2 svg
CONFIG += c++11
CONFIG += c++17
unix:!macx {
TARGET = moonlight

View File

@@ -58,7 +58,7 @@ void AutoUpdateChecker::start()
void AutoUpdateChecker::parseStringToVersionQuad(QString& string, QVector<int>& version)
{
QStringList list = string.split('.');
for (const QString& component : list) {
for (const QString& component : std::as_const(list)) {
version.append(component.toInt());
}
}
@@ -139,7 +139,7 @@ void AutoUpdateChecker::handleUpdateCheckRequestFinished(QNetworkReply* reply)
return;
}
for (QJsonValueRef updateEntry : array) {
for (const auto& updateEntry : std::as_const(array)) {
if (updateEntry.isObject()) {
QJsonObject updateObj = updateEntry.toObject();
if (!updateObj.contains("platform") ||

View File

@@ -231,17 +231,17 @@ ComputerManager::~ComputerManager()
m_MdnsBrowser = nullptr;
// Interrupt polling
for (ComputerPollingEntry* entry : m_PollEntries) {
for (ComputerPollingEntry* entry : std::as_const(m_PollEntries)) {
entry->interrupt();
}
// Delete all polling entries (and associated threads)
for (ComputerPollingEntry* entry : m_PollEntries) {
for (ComputerPollingEntry* entry : std::as_const(m_PollEntries)) {
delete entry;
}
// Destroy all NvComputer objects now that polling is halted
for (NvComputer* computer : m_KnownHosts) {
for (NvComputer* computer : std::as_const(m_KnownHosts)) {
delete computer;
}
}
@@ -268,7 +268,7 @@ void DelayedFlushThread::run() {
// Update the last serialized hosts map under the delayed flush mutex
m_ComputerManager->m_LastSerializedHosts.clear();
for (const NvComputer* computer : m_ComputerManager->m_KnownHosts) {
for (const NvComputer* computer : std::as_const(m_ComputerManager->m_KnownHosts)) {
// Copy the current state of the NvComputer to allow us to check later if we need
// to serialize it again when attribute updates occur.
QReadLocker computerLock(&computer->lock);
@@ -285,7 +285,7 @@ void DelayedFlushThread::run() {
{
QReadLocker lock(&m_ComputerManager->m_Lock);
int i = 0;
for (const NvComputer* computer : m_ComputerManager->m_KnownHosts) {
for (const NvComputer* computer : std::as_const(m_ComputerManager->m_KnownHosts)) {
settings.setArrayIndex(i++);
computer->serialize(settings, false);
}
@@ -298,7 +298,7 @@ void DelayedFlushThread::run() {
{
QReadLocker lock(&m_ComputerManager->m_Lock);
int i = 0;
for (const NvComputer* computer : m_ComputerManager->m_KnownHosts) {
for (const NvComputer* computer : std::as_const(m_ComputerManager->m_KnownHosts)) {
settings.setArrayIndex(i++);
computer->serialize(settings, true);
}
@@ -424,7 +424,7 @@ void ComputerManager::handleMdnsServiceResolved(MdnsPendingComputer* computer,
bool added = false;
// Add the host using the IPv4 address
for (const QHostAddress& address : addresses) {
for (const QHostAddress& address : std::as_const(addresses)) {
if (address.protocol() == QAbstractSocket::IPv4Protocol) {
// NB: We don't just call addNewHost() here with v6Global because the IPv6
// address may not be reachable (if the user hasn't installed the IPv6 helper yet
@@ -440,7 +440,7 @@ void ComputerManager::handleMdnsServiceResolved(MdnsPendingComputer* computer,
if (!added) {
// If we get here, there wasn't an IPv4 address so we'll do it v6-only
for (const QHostAddress& address : addresses) {
for (const QHostAddress& address : std::as_const(addresses)) {
if (address.protocol() == QAbstractSocket::IPv6Protocol) {
// Use a link-local or site-local address for the "local address"
if (address.isInSubnet(QHostAddress("fe80::"), 10) ||
@@ -569,7 +569,7 @@ void ComputerManager::handleAboutToQuit()
// Interrupt polling threads immediately, so they
// avoid making additional requests while quitting
for (ComputerPollingEntry* entry : m_PollEntries) {
for (ComputerPollingEntry* entry : std::as_const(m_PollEntries)) {
entry->interrupt();
}
}
@@ -721,7 +721,7 @@ void ComputerManager::stopPollingAsync()
m_MdnsServer.reset();
// Interrupt all threads, but don't wait for them to terminate
for (ComputerPollingEntry* entry : m_PollEntries) {
for (ComputerPollingEntry* entry : std::as_const(m_PollEntries)) {
entry->interrupt();
}
}

View File

@@ -150,7 +150,7 @@ public:
// interrupt() should have taken care of this
Q_ASSERT(m_ActiveThread == nullptr);
for (QThread* thread : m_InactiveList) {
for (QThread* thread : std::as_const(m_InactiveList)) {
thread->wait();
delete thread;
}

View File

@@ -7,7 +7,8 @@ ComputerSeeker::ComputerSeeker(ComputerManager *manager, QString computerName, Q
m_TimeoutTimer(new QTimer(this))
{
// If we know this computer, send a WOL packet to wake it up in case it is asleep.
for (NvComputer * computer: m_ComputerManager->getComputers()) {
const auto computers = m_ComputerManager->getComputers();
for (NvComputer* computer : computers) {
if (this->matchComputer(computer)) {
computer->wake();
}
@@ -51,7 +52,8 @@ bool ComputerSeeker::matchComputer(NvComputer *computer) const
return true;
}
for (const NvAddress& addr : computer->uniqueAddresses()) {
const auto uniqueAddresses = computer->uniqueAddresses();
for (const NvAddress& addr : uniqueAddresses) {
if (addr.address().toLower() == value || addr.toString().toLower() == value) {
return true;
}

View File

@@ -141,7 +141,7 @@ NvComputer::NvComputer(NvHTTP& http, QString serverInfo)
QString newMacString = NvHTTP::getXmlString(serverInfo, "mac");
if (newMacString != "00:00:00:00:00:00") {
QStringList macOctets = newMacString.split(':');
for (const QString& macOctet : macOctets) {
for (const QString& macOctet : std::as_const(macOctets)) {
this->macAddress.append((char) macOctet.toInt(nullptr, 16));
}
}
@@ -254,14 +254,16 @@ bool NvComputer::wake() const
// case the host has timed out in ARP entries.
QMap<QString, quint16> addressMap;
QSet<quint16> basePortSet;
for (const NvAddress& addr : uniqueAddresses()) {
const auto uniqueHostAddresses = uniqueAddresses();
for (const NvAddress& addr : uniqueHostAddresses) {
addressMap.insert(addr.address(), addr.port());
basePortSet.insert(addr.port());
}
addressMap.insert("255.255.255.255", 0);
// Try to broadcast on all available NICs
for (const QNetworkInterface& nic : QNetworkInterface::allInterfaces()) {
const auto allInterfaces = QNetworkInterface::allInterfaces();
for (const QNetworkInterface& nic : allInterfaces) {
// Ensure the interface is up and skip the loopback adapter
if ((nic.flags() & QNetworkInterface::IsUp) == 0 ||
(nic.flags() & QNetworkInterface::IsLoopBack) != 0) {
@@ -269,7 +271,8 @@ bool NvComputer::wake() const
}
QHostAddress allNodesMulticast("FF02::1");
for (const QNetworkAddressEntry& addr : nic.addressEntries()) {
const auto allInterfaceAddresses = nic.addressEntries();
for (const QNetworkAddressEntry& addr : allInterfaceAddresses) {
// Store the scope ID for this NIC if IPv6 is enabled
if (!addr.ip().scopeId().isEmpty()) {
allNodesMulticast.setScopeId(addr.ip().scopeId());
@@ -375,13 +378,15 @@ NvComputer::ReachabilityType NvComputer::getActiveAddressReachability() const
Q_ASSERT(!s.localAddress().isNull());
Q_ASSERT(!s.peerAddress().isNull());
for (const QNetworkInterface& nic : QNetworkInterface::allInterfaces()) {
const auto allInterfaces = QNetworkInterface::allInterfaces();
for (const QNetworkInterface& nic : allInterfaces) {
// Ensure the interface is up
if ((nic.flags() & QNetworkInterface::IsUp) == 0) {
continue;
}
for (const QNetworkAddressEntry& addr : nic.addressEntries()) {
const auto allInterfaceAddresses = nic.addressEntries();
for (const QNetworkAddressEntry& addr : allInterfaceAddresses) {
if (addr.ip() == s.localAddress()) {
qInfo() << "Found matching interface:" << nic.humanReadableName() << nic.hardwareAddress() << nic.flags();
@@ -463,7 +468,7 @@ bool NvComputer::updateAppList(QVector<NvApp> newAppList) {
}
// Propagate client-side attributes to the new app list
for (const NvApp& existingApp : appList) {
for (const NvApp& existingApp : std::as_const(appList)) {
for (NvApp& newApp : newAppList) {
if (existingApp.id == newApp.id) {
newApp.hidden = existingApp.hidden;

View File

@@ -162,7 +162,7 @@ public:
QString getCurrentAppName() const
{
for (const NvApp& app : m_Computer->appList) {
for (const NvApp& app : std::as_const(m_Computer->appList)) {
if (m_Computer->currentGameId == app.id) {
return app.name;
}

View File

@@ -120,7 +120,7 @@ void AppModel::quitRunningApp()
bool AppModel::isAppCurrentlyVisible(const NvApp& app)
{
for (const NvApp& visibleApp : m_VisibleApps) {
for (const NvApp& visibleApp : std::as_const(m_VisibleApps)) {
if (app.id == visibleApp.id) {
return true;
}
@@ -156,7 +156,7 @@ void AppModel::updateAppList(QVector<NvApp> newList)
const NvApp& existingApp = m_VisibleApps.at(i);
bool found = false;
for (const NvApp& newApp : newVisibleList) {
for (const NvApp& newApp : std::as_const(newVisibleList)) {
if (existingApp.id == newApp.id) {
// If the data changed, update it in our list
if (existingApp != newApp) {
@@ -178,7 +178,7 @@ void AppModel::updateAppList(QVector<NvApp> newList)
}
// Process additions now
for (const NvApp& newApp : newVisibleList) {
for (const NvApp& newApp : std::as_const(newVisibleList)) {
int insertionIndex = m_VisibleApps.size();
bool found = false;

View File

@@ -218,7 +218,7 @@ void SdlGamepadKeyNavigation::onPollingTimerFired()
}
// Handle analog sticks by polling
for (auto gc : m_Gamepads) {
for (auto gc : std::as_const(m_Gamepads)) {
short leftX = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTX);
short leftY = SDL_GameControllerGetAxis(gc, SDL_CONTROLLER_AXIS_LEFTY);
if (SDL_GetTicks() - m_LastAxisNavigationEventTime < AXIS_NAVIGATION_REPEAT_DELAY) {

View File

@@ -41,7 +41,7 @@ MappingManager::MappingManager()
#else
.split('\n', QString::SkipEmptyParts);
#endif
for (const QString& sdlMapping : sdlMappings) {
for (const QString& sdlMapping : std::as_const(sdlMappings)) {
SdlGamepadMapping mapping(sdlMapping);
addMapping(mapping);
}
@@ -99,7 +99,7 @@ void MappingManager::applyMappings()
}
QList<SdlGamepadMapping> mappings = m_Mappings.values();
for (const SdlGamepadMapping& mapping : mappings) {
for (const SdlGamepadMapping& mapping : std::as_const(mappings)) {
QString sdlMappingString = mapping.getSdlMappingString();
int ret = SDL_GameControllerAddMapping(qPrintable(sdlMappingString));
if (ret < 0) {

View File

@@ -261,7 +261,7 @@ void SdlInputHandler::raiseAllKeys()
"Raising %d keys",
(int)m_KeysDown.count());
for (auto keyDown : m_KeysDown) {
for (auto keyDown : std::as_const(m_KeysDown)) {
LiSendKeyboardEvent(keyDown, KEY_ACTION_UP, 0);
}

View File

@@ -1596,7 +1596,7 @@ bool Session::startConnectionAsync()
// the chosen resolution. Avoid that by disabling SOPS when it
// is not streaming a supported resolution.
enableGameOptimizations = false;
for (const NvDisplayMode &mode : m_Computer->displayModes) {
for (const NvDisplayMode &mode : std::as_const(m_Computer->displayModes)) {
if (mode.width == m_StreamConfig.width &&
mode.height == m_StreamConfig.height) {
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,

View File

@@ -18,7 +18,7 @@ public:
{
int value = 0;
for (const int & v : *this) {
for (const int v : *this) {
value |= v;
}

View File

@@ -213,7 +213,7 @@ void Pacer::handleVsync(int timeUntilNextVsyncMillis)
// frame history to drop frames only if consistently above the
// one queued frame mark.
if (m_MaxVideoFps >= m_DisplayFps) {
for (int queueHistoryEntry : m_PacingQueueHistory) {
for (int queueHistoryEntry : std::as_const(m_PacingQueueHistory)) {
if (queueHistoryEntry <= 1) {
// Be lenient as long as the queue length
// resolves before the end of frame history
@@ -360,7 +360,7 @@ void Pacer::renderFrame(AVFrame* frame)
}
else {
frameDropTarget = 0;
for (int queueHistoryEntry : m_RenderQueueHistory) {
for (int queueHistoryEntry : std::as_const(m_RenderQueueHistory)) {
if (queueHistoryEntry == 0) {
// Be lenient as long as the queue length
// resolves before the end of frame history