From 52635fca1d4780c657c8722d0b944d027c17b543 Mon Sep 17 00:00:00 2001 From: Herman Semenov Date: Tue, 2 Apr 2024 17:01:14 +0300 Subject: [PATCH] utils: rewrite on optimized function SplitString --- Common/StringUtils.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/Common/StringUtils.cpp b/Common/StringUtils.cpp index 1b840698d8..abf2970ce5 100644 --- a/Common/StringUtils.cpp +++ b/Common/StringUtils.cpp @@ -316,12 +316,15 @@ void SplitString(std::string_view str, const char delim, std::vector &output) { size_t next = 0; - for (size_t pos = 0, len = str.length(); pos < len; ++pos) { - if (str[pos] == delim) { - output.emplace_back(str.substr(next, pos - next)); - // Skip the delimiter itself. - next = pos + 1; + size_t pos = 0; + while (pos < str.length()) { + size_t delimPos = str.find(delim, pos); + if (delimPos == std::string_view::npos) { + break; } + output.emplace_back(str.substr(next, delimPos - next)); + next = delimPos + 1; + pos = delimPos + 1; } if (next == 0) {