summaryrefslogtreecommitdiff
path: root/ZAPDTR
diff options
context:
space:
mode:
authorDavid Chavez <david@dcvz.io>2022-07-26 03:12:25 +0200
committerGitHub <noreply@github.com>2022-07-25 21:12:25 -0400
commit8bdc4458c73898e17c738c82eb83402b26968ef0 (patch)
tree977905cc933f0a058947254a1dce98d25b4be619 /ZAPDTR
parent5f718932e616fa2f0aacbc411e8a44afddd2ee9a (diff)
Improve string split performance (#933)
Diffstat (limited to 'ZAPDTR')
-rw-r--r--ZAPDTR/ZAPDUtils/Utils/StringHelper.cpp30
1 files changed, 13 insertions, 17 deletions
diff --git a/ZAPDTR/ZAPDUtils/Utils/StringHelper.cpp b/ZAPDTR/ZAPDUtils/Utils/StringHelper.cpp
index 070fffa63..051e9a87d 100644
--- a/ZAPDTR/ZAPDUtils/Utils/StringHelper.cpp
+++ b/ZAPDTR/ZAPDUtils/Utils/StringHelper.cpp
@@ -9,22 +9,18 @@
std::vector<std::string> StringHelper::Split(std::string s, const std::string& delimiter)
{
- std::vector<std::string> result;
-
- size_t pos = 0;
- std::string token;
-
- while ((pos = s.find(delimiter)) != std::string::npos)
- {
- token = s.substr(0, pos);
- result.push_back(token);
- s.erase(0, pos + delimiter.length());
- }
-
- if (s.length() != 0)
- result.push_back(s);
-
- return result;
+ size_t pos_start = 0, pos_end, delim_len = delimiter.length();
+ std::string token;
+ std::vector<std::string> res;
+
+ while ((pos_end = s.find(delimiter, pos_start)) != std::string::npos) {
+ token = s.substr(pos_start, pos_end - pos_start);
+ pos_start = pos_end + delim_len;
+ res.push_back(token);
+ }
+
+ res.push_back(s.substr(pos_start));
+ return res;
}
std::string StringHelper::Strip(std::string s, const std::string& delimiter)
@@ -127,4 +123,4 @@ bool StringHelper::IEquals(const std::string& a, const std::string& b)
{
return std::equal(a.begin(), a.end(), b.begin(), b.end(),
[](char a, char b) { return tolower(a) == tolower(b); });
-} \ No newline at end of file
+}