From f0fa692457495481b778f3cc86bde300cd22ef12 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 21 Mar 2017 17:22:28 -0400 Subject: [PATCH 1/4] GeckoCodeConfig: Move gecko code title building to its own function Keeps it separate from the rest of the saving code and also allows for easy rvalue-reference moving into the lines vector as a side-benefit. --- Source/Core/Core/GeckoCodeConfig.cpp | 28 +++++++++++++--------------- 1 file changed, 13 insertions(+), 15 deletions(-) diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index f50b848d68..712b186b65 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -97,6 +97,18 @@ std::vector LoadCodes(const IniFile& globalIni, const IniFile& localI return gcodes; } +static std::string MakeGeckoCodeTitle(const GeckoCode& code) +{ + std::string title = '$' + code.name; + + if (!code.creator.empty()) + { + title += " [" + code.creator + ']'; + } + + return title; +} + // used by the SaveGeckoCodes function static void SaveGeckoCode(std::vector& lines, std::vector& enabledLines, const GeckoCode& gcode) @@ -107,21 +119,7 @@ static void SaveGeckoCode(std::vector& lines, std::vector Date: Tue, 21 Mar 2017 17:25:49 -0400 Subject: [PATCH 2/4] GeckoCodeConfig: Remove unused commented out code --- Source/Core/Core/GeckoCodeConfig.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index 712b186b65..436aa3133f 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -124,10 +124,7 @@ static void SaveGeckoCode(std::vector& lines, std::vectoraddress << ' ' << codes_iter->data; - // lines.push_back(StringFromFormat("%08X %08X", codes_iter->address, codes_iter->data)); lines.push_back(code.original_line); - // ss.clear(); } // save the notes From 0d0e9f626d1a1f5323d91062d4b4c360f78dd99b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 21 Mar 2017 17:30:01 -0400 Subject: [PATCH 3/4] GeckoCodeConfig: Amend unnecessary string literals to char literals Also gets rid of an unnecessary std::string construction in a loop. std::string already has an operator+ overload to prepend characters. --- Source/Core/Core/GeckoCodeConfig.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index 436aa3133f..70d65705ba 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -114,7 +114,7 @@ static void SaveGeckoCode(std::vector& lines, std::vector& lines, std::vector& gcodes) From 2f52d04e3044accf0656a32c2090e625e3f76c8b Mon Sep 17 00:00:00 2001 From: Lioncash Date: Tue, 21 Mar 2017 17:51:22 -0400 Subject: [PATCH 4/4] GeckoCodeConfig: Use compare instead of substr for comparing substrings Gets rid of an unnecessary string construction. --- Source/Core/Core/GeckoCodeConfig.cpp | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Source/Core/Core/GeckoCodeConfig.cpp b/Source/Core/Core/GeckoCodeConfig.cpp index 70d65705ba..8cae3d8b68 100644 --- a/Source/Core/Core/GeckoCodeConfig.cpp +++ b/Source/Core/Core/GeckoCodeConfig.cpp @@ -79,14 +79,15 @@ std::vector LoadCodes(const IniFile& globalIni, const IniFile& localI for (const std::string& line : lines) { - if (line.size() == 0 || line[0] != '$') + if (line.empty() || line[0] != '$') { continue; } - std::string name = line.substr(1); + for (GeckoCode& ogcode : gcodes) { - if (ogcode.name == name) + // Exclude the initial '$' from the comparison. + if (line.compare(1, std::string::npos, ogcode.name) == 0) { ogcode.enabled = true; }