summaryrefslogtreecommitdiff
path: root/src/common/string_util.cpp
diff options
context:
space:
mode:
authorGravatar Lioncash2018-07-22 15:33:07 -0400
committerGravatar Lioncash2018-07-22 15:35:48 -0400
commitcd46b267f5715c0900b409d7bcb97f6bc9a43d9e (patch)
tree6c97e3a7e2727ebbbb84af10b16d1902ff0d283d /src/common/string_util.cpp
parentMerge pull request #773 from Subv/gl_ext_check (diff)
downloadyuzu-cd46b267f5715c0900b409d7bcb97f6bc9a43d9e.tar.gz
yuzu-cd46b267f5715c0900b409d7bcb97f6bc9a43d9e.tar.xz
yuzu-cd46b267f5715c0900b409d7bcb97f6bc9a43d9e.zip
string_util: Remove unnecessary std::string instance in TabsToSpaces()
We can just use the variant of std::string's replace() function that can replace an occurrence with N copies of the same character, eliminating the need to allocate a std::string containing a buffer of spaces.
Diffstat (limited to 'src/common/string_util.cpp')
-rw-r--r--src/common/string_util.cpp13
1 files changed, 6 insertions, 7 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index f3ad3d68a..2099eebb8 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -168,15 +168,14 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
168 output.pop_back(); 168 output.pop_back();
169} 169}
170 170
171std::string TabsToSpaces(int tab_size, const std::string& in) { 171std::string TabsToSpaces(int tab_size, std::string in) {
172 const std::string spaces(tab_size, ' ');
173 std::string out(in);
174
175 size_t i = 0; 172 size_t i = 0;
176 while (out.npos != (i = out.find('\t')))
177 out.replace(i, 1, spaces);
178 173
179 return out; 174 while ((i = in.find('\t')) != std::string::npos) {
175 in.replace(i, 1, tab_size, ' ');
176 }
177
178 return in;
180} 179}
181 180
182std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) { 181std::string ReplaceAll(std::string result, const std::string& src, const std::string& dest) {