util/SplitString: convert return value to std::string_view

Eliminates lots of overhead.
This commit is contained in:
Max Kellermann
2020-04-03 16:42:49 +02:00
parent 2c02a04566
commit db93bb996c
8 changed files with 27 additions and 32 deletions
+5 -9
View File
@@ -31,28 +31,24 @@
#include "IterableSplitString.hxx"
#include "StringStrip.hxx"
std::forward_list<std::string>
std::forward_list<std::string_view>
SplitString(std::string_view _s, char separator, bool strip) noexcept
{
StringView s(_s);
if (strip)
s.StripLeft();
std::forward_list<std::string> list;
std::forward_list<std::string_view> list;
if (s.empty())
return list;
auto i = list.before_begin();
for (auto value : IterableSplitString(s, separator)) {
const char *begin = value.begin(), *end = value.end();
if (strip)
value.Strip();
if (strip) {
begin = StripLeft(begin, end);
end = StripRight(begin, end);
}
i = list.emplace_after(i, begin, end);
i = list.emplace_after(i, value);
}
return list;