Skip to content

Commit

Permalink
Merge pull request #18541 from hrydgard/const-ref
Browse files Browse the repository at this point in the history
Using const reference for C++17 range-based loop and freq used objects
  • Loading branch information
hrydgard committed Dec 13, 2023
2 parents da318e0 + 315340f commit c2a7622
Show file tree
Hide file tree
Showing 13 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion Common/CPUDetect.cpp
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Common/GPU/Vulkan/VulkanLoader.cpp
Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions Common/UI/Screen.cpp
Expand Up @@ -259,10 +259,10 @@ void ScreenManager::sendMessage(UIMessage message, const char *value) {

void ScreenManager::shutdown() {
std::lock_guard<std::recursive_mutex> 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_;
Expand Down
4 changes: 2 additions & 2 deletions Core/Debugger/WebSocket/HLESubscriber.cpp
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion Core/Dialog/SavedataParam.cpp
Expand Up @@ -880,7 +880,7 @@ std::set<std::string> SavedataParam::GetSecureFileNames(const std::string &dirPa
auto entries = GetSFOEntries(dirPath);

std::set<std::string> secureFileNames;
for (auto entry : entries) {
for (const auto &entry : entries) {
char temp[14];
truncate_cpy(temp, entry.filename);
secureFileNames.insert(temp);
Expand Down
4 changes: 2 additions & 2 deletions Core/HLE/sceFont.cpp
Expand Up @@ -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) {
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion Core/HLE/sceKernelModule.cpp
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions GPU/Common/PostShader.cpp
Expand Up @@ -291,8 +291,8 @@ std::vector<const ShaderInfo *> GetPostShaderChain(const std::string &name) {

std::vector<const ShaderInfo *> GetFullPostShadersChain(const std::vector<std::string> &names) {
std::vector<const ShaderInfo *> 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;
Expand Down
2 changes: 1 addition & 1 deletion GPU/Common/VertexDecoderCommon.cpp
Expand Up @@ -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";
}
Expand Down
2 changes: 1 addition & 1 deletion GPU/GLES/ShaderManagerGLES.cpp
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions UI/DevScreens.cpp
Expand Up @@ -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);
}
}
Expand Down Expand Up @@ -1377,7 +1377,7 @@ void ShaderViewScreen::CreateViews() {
std::vector<std::string> 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));
}

Expand Down
2 changes: 1 addition & 1 deletion UI/GameScreen.cpp
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion UI/ReportScreen.cpp
Expand Up @@ -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");
Expand Down

0 comments on commit c2a7622

Please sign in to comment.