util/SplitString: convert return value to std::string_view
Eliminates lots of overhead.
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -31,7 +31,6 @@
|
||||
#define SPLIT_STRING_HXX
|
||||
|
||||
#include <forward_list>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
|
||||
/**
|
||||
@@ -44,7 +43,7 @@
|
||||
* An empty input string, as a special case, results in an empty list
|
||||
* (and not a list with an empty string).
|
||||
*/
|
||||
std::forward_list<std::string>
|
||||
std::forward_list<std::string_view>
|
||||
SplitString(std::string_view s, char separator, bool strip=true) noexcept;
|
||||
|
||||
#endif
|
||||
|
||||
Reference in New Issue
Block a user