diff options
author | Max Kellermann <max@musicpd.org> | 2020-04-03 16:42:49 +0200 |
---|---|---|
committer | Max Kellermann <max@musicpd.org> | 2020-04-08 23:14:25 +0200 |
commit | db93bb996c885496bc2076b36b86b726ae0879ed (patch) | |
tree | 1965eae1cc64b0abfca96cb4544582b6b9a118fb /src/util | |
parent | 2c02a0456661aa79ebd92c9d05b7011b7c1fb147 (diff) |
util/SplitString: convert return value to std::string_view
Eliminates lots of overhead.
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/SplitString.cxx | 14 | ||||
-rw-r--r-- | src/util/SplitString.hxx | 3 |
2 files changed, 6 insertions, 11 deletions
diff --git a/src/util/SplitString.cxx b/src/util/SplitString.cxx index 5676b098f..821ba1af8 100644 --- a/src/util/SplitString.cxx +++ b/src/util/SplitString.cxx @@ -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; diff --git a/src/util/SplitString.hxx b/src/util/SplitString.hxx index 7ecc8997e..8e22ee457 100644 --- a/src/util/SplitString.hxx +++ b/src/util/SplitString.hxx @@ -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 |