Commit 78a65cf2 authored by Max Kellermann's avatar Max Kellermann

SongFilter: remove DetachedSong overloads

All DetachedSong instances should be converted to LightSong first, which is a very cheap operation.
parent 96017f58
...@@ -20,8 +20,8 @@ ...@@ -20,8 +20,8 @@
#include "config.h" #include "config.h"
#include "SongFilter.hxx" #include "SongFilter.hxx"
#include "db/LightSong.hxx" #include "db/LightSong.hxx"
#include "DetachedSong.hxx"
#include "tag/ParseName.hxx" #include "tag/ParseName.hxx"
#include "tag/Tag.hxx"
#include "util/CharUtil.hxx" #include "util/CharUtil.hxx"
#include "util/ChronoUtil.hxx" #include "util/ChronoUtil.hxx"
#include "util/ConstBuffer.hxx" #include "util/ConstBuffer.hxx"
...@@ -158,21 +158,6 @@ SongFilter::Item::MatchNN(const Tag &_tag) const noexcept ...@@ -158,21 +158,6 @@ SongFilter::Item::MatchNN(const Tag &_tag) const noexcept
} }
bool bool
SongFilter::Item::MatchNN(const DetachedSong &song) const noexcept
{
if (tag == LOCATE_TAG_BASE_TYPE)
return uri_is_child_or_same(value.c_str(), song.GetURI());
if (tag == LOCATE_TAG_MODIFIED_SINCE)
return song.GetLastModified() >= time;
if (tag == LOCATE_TAG_FILE_TYPE)
return StringMatchNN(song.GetURI());
return MatchNN(song.GetTag());
}
bool
SongFilter::Item::MatchNN(const LightSong &song) const noexcept SongFilter::Item::MatchNN(const LightSong &song) const noexcept
{ {
if (tag == LOCATE_TAG_BASE_TYPE) { if (tag == LOCATE_TAG_BASE_TYPE) {
...@@ -381,16 +366,6 @@ SongFilter::Parse(ConstBuffer<const char *> args, bool fold_case) ...@@ -381,16 +366,6 @@ SongFilter::Parse(ConstBuffer<const char *> args, bool fold_case)
} }
bool bool
SongFilter::Match(const DetachedSong &song) const noexcept
{
for (const auto &i : items)
if (!i.Match(song))
return false;
return true;
}
bool
SongFilter::Match(const LightSong &song) const noexcept SongFilter::Match(const LightSong &song) const noexcept
{ {
for (const auto &i : items) for (const auto &i : items)
......
...@@ -45,7 +45,6 @@ template<typename T> struct ConstBuffer; ...@@ -45,7 +45,6 @@ template<typename T> struct ConstBuffer;
struct Tag; struct Tag;
struct TagItem; struct TagItem;
struct LightSong; struct LightSong;
class DetachedSong;
class SongFilter { class SongFilter {
public: public:
...@@ -111,16 +110,12 @@ public: ...@@ -111,16 +110,12 @@ public:
bool MatchNN(const Tag &tag) const noexcept; bool MatchNN(const Tag &tag) const noexcept;
gcc_pure gcc_pure
bool MatchNN(const DetachedSong &song) const noexcept;
gcc_pure
bool MatchNN(const LightSong &song) const noexcept; bool MatchNN(const LightSong &song) const noexcept;
public: public:
template<typename T>
gcc_pure gcc_pure
bool Match(const T &t) const noexcept { bool Match(const LightSong &song) const noexcept {
return MatchNN(t) != IsNegated(); return MatchNN(song) != IsNegated();
} }
}; };
...@@ -154,9 +149,6 @@ public: ...@@ -154,9 +149,6 @@ public:
void Parse(ConstBuffer<const char *> args, bool fold_case=false); void Parse(ConstBuffer<const char *> args, bool fold_case=false);
gcc_pure gcc_pure
bool Match(const DetachedSong &song) const noexcept;
gcc_pure
bool Match(const LightSong &song) const noexcept; bool Match(const LightSong &song) const noexcept;
const std::list<Item> &GetItems() const noexcept { const std::list<Item> &GetItems() const noexcept {
......
...@@ -22,6 +22,8 @@ ...@@ -22,6 +22,8 @@
#include "Queue.hxx" #include "Queue.hxx"
#include "SongFilter.hxx" #include "SongFilter.hxx"
#include "SongPrint.hxx" #include "SongPrint.hxx"
#include "DetachedSong.hxx"
#include "db/LightSong.hxx"
#include "client/Response.hxx" #include "client/Response.hxx"
/** /**
...@@ -111,7 +113,7 @@ queue_find(Response &r, const Queue &queue, ...@@ -111,7 +113,7 @@ queue_find(Response &r, const Queue &queue,
const SongFilter &filter) const SongFilter &filter)
{ {
for (unsigned i = 0; i < queue.GetLength(); i++) { for (unsigned i = 0; i < queue.GetLength(); i++) {
const DetachedSong &song = queue.Get(i); const LightSong song{queue.Get(i)};
if (filter.Match(song)) if (filter.Match(song))
queue_print_song_info(r, queue, i); queue_print_song_info(r, queue, i);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment