From 315340fc62985bb38ea783594fd008a73f6aff1c Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Tue, 12 Dec 2023 17:38:50 +0300 Subject: [PATCH] Using const reference for C++17 range-based loop and freq used objects --- Common/CPUDetect.cpp | 2 +- Common/GPU/Vulkan/VulkanLoader.cpp | 2 +- Common/UI/Screen.cpp | 4 ++-- Core/Debugger/WebSocket/HLESubscriber.cpp | 4 ++-- Core/Dialog/SavedataParam.cpp | 2 +- Core/HLE/sceFont.cpp | 4 ++-- Core/HLE/sceKernelModule.cpp | 2 +- GPU/Common/PostShader.cpp | 4 ++-- GPU/Common/VertexDecoderCommon.cpp | 2 +- GPU/GLES/ShaderManagerGLES.cpp | 2 +- UI/DevScreens.cpp | 8 ++++---- UI/GameScreen.cpp | 2 +- UI/ReportScreen.cpp | 2 +- 13 files changed, 20 insertions(+), 20 deletions(-) diff --git a/Common/CPUDetect.cpp b/Common/CPUDetect.cpp index 2628f91d46c2..b0c3625afd39 100644 --- a/Common/CPUDetect.cpp +++ b/Common/CPUDetect.cpp @@ -426,7 +426,7 @@ void CPUInfo::Detect() { if (GetLogicalProcessorInformation(&processors[0], &len)) { num_cores = 0; logical_cpu_count = 0; - for (auto processor : processors) { + for (const auto &processor : processors) { if (processor.Relationship == RelationProcessorCore) { num_cores++; for (int i = 0; i < sizeof(processor.ProcessorMask) * 8; ++i) { diff --git a/Common/GPU/Vulkan/VulkanLoader.cpp b/Common/GPU/Vulkan/VulkanLoader.cpp index 3c7069c4a1cc..f951c79332cd 100644 --- a/Common/GPU/Vulkan/VulkanLoader.cpp +++ b/Common/GPU/Vulkan/VulkanLoader.cpp @@ -404,7 +404,7 @@ bool VulkanMayBeAvailable() { ERROR_LOG(G3D, "Enumerating VK extensions failed (%s)", VulkanResultToString(res)); goto bail; } - for (auto iter : instanceExts) { + for (const auto &iter : instanceExts) { INFO_LOG(G3D, "VulkanMaybeAvailable: Instance extension found: %s (%08x)", iter.extensionName, iter.specVersion); if (platformSurfaceExtension && !strcmp(iter.extensionName, platformSurfaceExtension)) { INFO_LOG(G3D, "VulkanMayBeAvailable: Found platform surface extension '%s'", platformSurfaceExtension); diff --git a/Common/UI/Screen.cpp b/Common/UI/Screen.cpp index fd65cdf71120..c5f1a7be7289 100644 --- a/Common/UI/Screen.cpp +++ b/Common/UI/Screen.cpp @@ -259,10 +259,10 @@ void ScreenManager::sendMessage(UIMessage message, const char *value) { void ScreenManager::shutdown() { std::lock_guard guard(inputLock_); - for (auto layer : stack_) + for (const auto &layer : stack_) delete layer.screen; stack_.clear(); - for (auto layer : nextStack_) + for (const auto &layer : nextStack_) delete layer.screen; nextStack_.clear(); delete overlayScreen_; diff --git a/Core/Debugger/WebSocket/HLESubscriber.cpp b/Core/Debugger/WebSocket/HLESubscriber.cpp index 0efe01b2227a..8e749f19f5e3 100644 --- a/Core/Debugger/WebSocket/HLESubscriber.cpp +++ b/Core/Debugger/WebSocket/HLESubscriber.cpp @@ -68,7 +68,7 @@ void WebSocketHLEThreadList(DebuggerRequest &req) { JsonWriter &json = req.Respond(); json.pushArray("threads"); - for (auto th : threads) { + for (const auto &th : threads) { json.pushDict(); json.writeUint("id", th.id); json.writeString("name", th.name); @@ -114,7 +114,7 @@ static bool ThreadInfoForStatus(DebuggerRequest &req, DebugThreadInfo *result) { return false; auto threads = GetThreadsInfo(); - for (auto t : threads) { + for (const auto &t : threads) { if (t.id == threadID) { *result = t; return true; diff --git a/Core/Dialog/SavedataParam.cpp b/Core/Dialog/SavedataParam.cpp index 58f107b21894..3e250480ca2b 100644 --- a/Core/Dialog/SavedataParam.cpp +++ b/Core/Dialog/SavedataParam.cpp @@ -880,7 +880,7 @@ std::set SavedataParam::GetSecureFileNames(const std::string &dirPa auto entries = GetSFOEntries(dirPath); std::set secureFileNames; - for (auto entry : entries) { + for (const auto &entry : entries) { char temp[14]; truncate_cpy(temp, entry.filename); secureFileNames.insert(temp); diff --git a/Core/HLE/sceFont.cpp b/Core/HLE/sceFont.cpp index ffd89f69fc92..7259bd2d8d3b 100644 --- a/Core/HLE/sceFont.cpp +++ b/Core/HLE/sceFont.cpp @@ -1192,7 +1192,7 @@ static int sceFontFindOptimumFont(u32 libHandle, u32 fontStylePtr, u32 errorCode for (size_t i = 0; i < internalFonts.size(); i++) { MatchQuality q = internalFonts[i]->MatchesStyle(*requestedStyle); if (q != MATCH_NONE) { - auto matchStyle = internalFonts[i]->GetFontStyle(); + const auto &matchStyle = internalFonts[i]->GetFontStyle(); if (requestedStyle->fontH > 0.0f) { float hDist = fabs(matchStyle.fontHRes * matchStyle.fontH - hRes * requestedStyle->fontH); if (hDist < nearestDist) { @@ -1255,7 +1255,7 @@ static int sceFontFindFont(u32 libHandle, u32 fontStylePtr, u32 errorCodePtr) { float hRes = requestedStyle->fontHRes > 0.0f ? (float)requestedStyle->fontHRes : fontLib->FontHRes(); for (size_t i = 0; i < internalFonts.size(); i++) { if (internalFonts[i]->MatchesStyle(*requestedStyle) != MATCH_NONE) { - auto matchStyle = internalFonts[i]->GetFontStyle(); + const auto &matchStyle = internalFonts[i]->GetFontStyle(); if (requestedStyle->fontH > 0.0f) { float hDist = fabs(matchStyle.fontHRes * matchStyle.fontH - hRes * requestedStyle->fontH); if (hDist > 0.001f) { diff --git a/Core/HLE/sceKernelModule.cpp b/Core/HLE/sceKernelModule.cpp index 87cf486f4a95..6143522da12d 100644 --- a/Core/HLE/sceKernelModule.cpp +++ b/Core/HLE/sceKernelModule.cpp @@ -354,7 +354,7 @@ class PSPModule : public KernelObject { bool foundBroken = false; auto importedFuncsState = importedFuncs; importedFuncs.clear(); - for (auto func : importedFuncsState) { + for (const auto &func : importedFuncsState) { if (func.moduleName[KERNELOBJECT_MAX_NAME_LENGTH] != '\0' || !Memory::IsValidAddress(func.stubAddr)) { foundBroken = true; } else { diff --git a/GPU/Common/PostShader.cpp b/GPU/Common/PostShader.cpp index 113aa662ac5b..8cf0967e3366 100644 --- a/GPU/Common/PostShader.cpp +++ b/GPU/Common/PostShader.cpp @@ -291,8 +291,8 @@ std::vector GetPostShaderChain(const std::string &name) { std::vector GetFullPostShadersChain(const std::vector &names) { std::vector fullChain; - for (auto shaderName : names) { - auto shaderChain = GetPostShaderChain(shaderName); + for (const auto &shaderName : names) { + const auto &shaderChain = GetPostShaderChain(shaderName); fullChain.insert(fullChain.end(), shaderChain.begin(), shaderChain.end()); } return fullChain; diff --git a/GPU/Common/VertexDecoderCommon.cpp b/GPU/Common/VertexDecoderCommon.cpp index e500c69db5fa..986276f4b699 100644 --- a/GPU/Common/VertexDecoderCommon.cpp +++ b/GPU/Common/VertexDecoderCommon.cpp @@ -1501,7 +1501,7 @@ std::string VertexDecoder::GetString(DebugShaderStringType stringType) { // No disassembler defined #endif std::string buffer; - for (auto line : lines) { + for (const auto &line : lines) { buffer += line; buffer += "\n"; } diff --git a/GPU/GLES/ShaderManagerGLES.cpp b/GPU/GLES/ShaderManagerGLES.cpp index a684e7a6beb7..6f69d80c6d16 100644 --- a/GPU/GLES/ShaderManagerGLES.cpp +++ b/GPU/GLES/ShaderManagerGLES.cpp @@ -1192,7 +1192,7 @@ void ShaderManagerGLES::SaveCache(const Path &filename, DrawEngineGLES *drawEngi fsCache_.Iterate([&](const ShaderID &id, Shader *shader) { fwrite(&id, 1, sizeof(id), f); }); - for (auto iter : linkedShaderCache_) { + for (const auto &iter : linkedShaderCache_) { ShaderID vsid, fsid; vsCache_.Iterate([&](const ShaderID &id, Shader *shader) { if (iter.vs == shader) diff --git a/UI/DevScreens.cpp b/UI/DevScreens.cpp index 891f71f47f0f..ff91a4de784a 100644 --- a/UI/DevScreens.cpp +++ b/UI/DevScreens.cpp @@ -1114,17 +1114,17 @@ void JitCompareScreen::UpdateDisasm() { // Alright. First generate the MIPS disassembly. // TODO: Need a way to communicate branch continuing. - for (auto line : debugInfo.origDisasm) { + for (const auto &line : debugInfo.origDisasm) { leftDisasm_->Add(new TextView(line))->SetFocusable(true); } // TODO : When we have both target and IR, need a third column. if (debugInfo.targetDisasm.size()) { - for (auto line : debugInfo.targetDisasm) { + for (const auto &line : debugInfo.targetDisasm) { rightDisasm_->Add(new TextView(line))->SetFocusable(true); } } else { - for (auto line : debugInfo.irDisasm) { + for (const auto &line : debugInfo.irDisasm) { rightDisasm_->Add(new TextView(line))->SetFocusable(true); } } @@ -1377,7 +1377,7 @@ void ShaderViewScreen::CreateViews() { std::vector lines; SplitString(gpu->DebugGetShaderString(id_, type_, SHADER_STRING_SOURCE_CODE), '\n', lines); - for (auto line : lines) { + for (const auto &line : lines) { lineLayout->Add(new TextView(line, FLAG_DYNAMIC_ASCII | FLAG_WRAP_TEXT, true)); } diff --git a/UI/GameScreen.cpp b/UI/GameScreen.cpp index 76ebc4efc6c7..59a45455fa14 100644 --- a/UI/GameScreen.cpp +++ b/UI/GameScreen.cpp @@ -511,7 +511,7 @@ bool GameScreen::isRecentGame(const Path &gamePath) { return false; const std::string resolved = File::ResolvePath(gamePath.ToString()); - for (auto iso : g_Config.RecentIsos()) { + for (const auto &iso : g_Config.RecentIsos()) { const std::string recent = File::ResolvePath(iso); if (resolved == recent) return true; diff --git a/UI/ReportScreen.cpp b/UI/ReportScreen.cpp index cff056929065..a1785f4363f4 100644 --- a/UI/ReportScreen.cpp +++ b/UI/ReportScreen.cpp @@ -485,7 +485,7 @@ void ReportFinishScreen::ShowSuggestions() { resultItems_->Clear(); bool shownConfig = false; bool valid = false; - for (auto item : suggestions) { + for (const auto &item : suggestions) { const char *suggestion = nullptr; if (item == "Upgrade") { suggestion = rp->T("SuggestionUpgrade", "Upgrade to a newer PPSSPP build");