From 6197b29aa0a165129f553c00c78af564fd624e21 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Thu, 2 Apr 2020 19:46:19 +0200 Subject: [PATCH] db/PlaylistInfo: pass std::string_view to CompareName --- src/db/PlaylistInfo.hxx | 8 +++++--- src/db/PlaylistVector.cxx | 5 ++--- src/db/PlaylistVector.hxx | 5 +++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/db/PlaylistInfo.hxx b/src/db/PlaylistInfo.hxx index 368f34758..92a4d8b18 100644 --- a/src/db/PlaylistInfo.hxx +++ b/src/db/PlaylistInfo.hxx @@ -23,6 +23,7 @@ #include "util/Compiler.h" #include +#include #include /** @@ -42,14 +43,15 @@ struct PlaylistInfo { std::chrono::system_clock::time_point::min(); class CompareName { - const char *const name; + const std::string_view name; public: - constexpr CompareName(const char *_name):name(_name) {} + constexpr CompareName(std::string_view _name) noexcept + :name(_name) {} gcc_pure bool operator()(const PlaylistInfo &pi) const noexcept { - return pi.name.compare(name) == 0; + return pi.name == name; } }; diff --git a/src/db/PlaylistVector.cxx b/src/db/PlaylistVector.cxx index 9197a004d..9c2697741 100644 --- a/src/db/PlaylistVector.cxx +++ b/src/db/PlaylistVector.cxx @@ -24,10 +24,9 @@ #include PlaylistVector::iterator -PlaylistVector::find(const char *name) noexcept +PlaylistVector::find(std::string_view name) noexcept { assert(holding_db_lock()); - assert(name != nullptr); return std::find_if(begin(), end(), PlaylistInfo::CompareName(name)); @@ -51,7 +50,7 @@ PlaylistVector::UpdateOrInsert(PlaylistInfo &&pi) noexcept } bool -PlaylistVector::erase(const char *name) noexcept +PlaylistVector::erase(std::string_view name) noexcept { assert(holding_db_lock()); diff --git a/src/db/PlaylistVector.hxx b/src/db/PlaylistVector.hxx index 5e255d028..58982c546 100644 --- a/src/db/PlaylistVector.hxx +++ b/src/db/PlaylistVector.hxx @@ -24,6 +24,7 @@ #include "util/Compiler.h" #include +#include class PlaylistVector : protected std::list { protected: @@ -31,7 +32,7 @@ protected: * Caller must lock the #db_mutex. */ gcc_pure - iterator find(const char *name) noexcept; + iterator find(std::string_view name) noexcept; public: using std::list::empty; @@ -50,7 +51,7 @@ public: /** * Caller must lock the #db_mutex. */ - bool erase(const char *name) noexcept; + bool erase(std::string_view name) noexcept; }; #endif /* SONGVEC_H */