aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLioncash <mathew1800@gmail.com>2018-07-22 15:36:30 -0400
committerLioncash <mathew1800@gmail.com>2018-07-22 15:36:32 -0400
commitcd098960571dd70e3239bbeebb1180c8cbd2620e (patch)
tree50a66cdeb25823c1f4b7bcf496bb8e92f08bd2e2
parent7b00b5c32245d0f0df525ae58ec36899ff2a9842 (diff)
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.
-rw-r--r--src/common/string_util.cpp5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/common/string_util.cpp b/src/common/string_util.cpp
index 2099eebb8b..6737655a54 100644
--- a/src/common/string_util.cpp
+++ b/src/common/string_util.cpp
@@ -162,8 +162,9 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
std::istringstream iss(str);
output.resize(1);
- while (std::getline(iss, *output.rbegin(), delim))
- output.push_back("");
+ while (std::getline(iss, *output.rbegin(), delim)) {
+ output.emplace_back();
+ }
output.pop_back();
}