Path: Use string_view more to avoid allocations
This commit is contained in:
parent
70c7bb3b0d
commit
d0ee5fc308
8 changed files with 39 additions and 36 deletions
|
@ -284,8 +284,7 @@ std::string_view StripQuotes(std::string_view s) {
|
|||
return s;
|
||||
}
|
||||
|
||||
void SplitString(const std::string& str, const char delim, std::vector<std::string>& output)
|
||||
{
|
||||
void SplitString(std::string_view str, const char delim, std::vector<std::string> &output) {
|
||||
size_t next = 0;
|
||||
for (size_t pos = 0, len = str.length(); pos < len; ++pos) {
|
||||
if (str[pos] == delim) {
|
||||
|
@ -296,7 +295,7 @@ void SplitString(const std::string& str, const char delim, std::vector<std::stri
|
|||
}
|
||||
|
||||
if (next == 0) {
|
||||
output.push_back(str);
|
||||
output.push_back(std::string(str));
|
||||
} else if (next < str.length()) {
|
||||
output.emplace_back(str.substr(next));
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue