filter/chain: pass std::string_view to filter_chain_append()

This commit is contained in:
Max Kellermann 2020-11-04 16:29:13 +01:00
parent eeaec99c59
commit f2b9785a67
3 changed files with 11 additions and 8 deletions

View File

@ -27,10 +27,13 @@
static void static void
filter_chain_append_new(PreparedFilter &chain, FilterFactory &factory, filter_chain_append_new(PreparedFilter &chain, FilterFactory &factory,
const char *template_name) std::string_view template_name)
{ {
filter_chain_append(chain, template_name, filter_chain_append(chain, template_name,
factory.MakeFilter(template_name)); /* unfortunately, MakeFilter() wants a
null-terminated string, so we need to
copy it here */
factory.MakeFilter(std::string(template_name).c_str()));
} }
void void
@ -42,7 +45,6 @@ filter_chain_parse(PreparedFilter &chain,
if (i.empty()) if (i.empty())
continue; continue;
const std::string name(i); filter_chain_append_new(chain, factory, i);
filter_chain_append_new(chain, factory, name.c_str());
} }
} }

View File

@ -76,7 +76,7 @@ class PreparedChainFilter final : public PreparedFilter {
const std::string name; const std::string name;
std::unique_ptr<PreparedFilter> filter; std::unique_ptr<PreparedFilter> filter;
Child(const char *_name, Child(std::string_view _name,
std::unique_ptr<PreparedFilter> _filter) std::unique_ptr<PreparedFilter> _filter)
:name(_name), filter(std::move(_filter)) {} :name(_name), filter(std::move(_filter)) {}
@ -89,7 +89,7 @@ class PreparedChainFilter final : public PreparedFilter {
std::list<Child> children; std::list<Child> children;
public: public:
void Append(const char *name, void Append(std::string_view name,
std::unique_ptr<PreparedFilter> filter) noexcept { std::unique_ptr<PreparedFilter> filter) noexcept {
children.emplace_back(name, std::move(filter)); children.emplace_back(name, std::move(filter));
} }
@ -175,7 +175,7 @@ filter_chain_new() noexcept
} }
void void
filter_chain_append(PreparedFilter &_chain, const char *name, filter_chain_append(PreparedFilter &_chain, std::string_view name,
std::unique_ptr<PreparedFilter> filter) noexcept std::unique_ptr<PreparedFilter> filter) noexcept
{ {
auto &chain = (PreparedChainFilter &)_chain; auto &chain = (PreparedChainFilter &)_chain;

View File

@ -28,6 +28,7 @@
#define MPD_FILTER_CHAIN_HXX #define MPD_FILTER_CHAIN_HXX
#include <memory> #include <memory>
#include <string_view>
class PreparedFilter; class PreparedFilter;
@ -45,7 +46,7 @@ filter_chain_new() noexcept;
* @param filter the filter to be appended to #chain * @param filter the filter to be appended to #chain
*/ */
void void
filter_chain_append(PreparedFilter &chain, const char *name, filter_chain_append(PreparedFilter &chain, std::string_view name,
std::unique_ptr<PreparedFilter> filter) noexcept; std::unique_ptr<PreparedFilter> filter) noexcept;
#endif #endif