db/PlaylistInfo: pass std::string_view to CompareName
This commit is contained in:
parent
02294a8236
commit
6197b29aa0
@ -23,6 +23,7 @@
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <chrono>
|
||||
|
||||
/**
|
||||
@ -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;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -24,10 +24,9 @@
|
||||
#include <cassert>
|
||||
|
||||
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());
|
||||
|
||||
|
@ -24,6 +24,7 @@
|
||||
#include "util/Compiler.h"
|
||||
|
||||
#include <list>
|
||||
#include <string_view>
|
||||
|
||||
class PlaylistVector : protected std::list<PlaylistInfo> {
|
||||
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<PlaylistInfo>::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 */
|
||||
|
Loading…
Reference in New Issue
Block a user