Skip to content
Snippets Groups Projects
Commit 26a157cd authored by Lioncash's avatar Lioncash
Browse files

string_util: Use emplace_back() in SplitString() instead of push_back()

This is equivalent to doing:

push_back(std::string(""));

which is likely not to cause issues, assuming a decent std::string
implementation with small-string optimizations implemented in its
design, however it's still a little unnecessary to copy that buffer
regardless. Instead, we can use emplace_back() to directly construct the
empty string within the std::vector instance, eliminating any possible
overhead from the copy.
parent cd46b267
No related branches found
No related tags found
No related merge requests found
...@@ -162,8 +162,9 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri ...@@ -162,8 +162,9 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
std::istringstream iss(str); std::istringstream iss(str);
output.resize(1); output.resize(1);
while (std::getline(iss, *output.rbegin(), delim)) while (std::getline(iss, *output.rbegin(), delim)) {
output.push_back(""); output.emplace_back();
}
output.pop_back(); output.pop_back();
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment