Skip to content

Commit

Permalink
Merge branch 'tag-compare' of https://github.com/geneticdrift/MPD
Browse files Browse the repository at this point in the history
  • Loading branch information
MaxKellermann committed Jan 29, 2025
2 parents a404e57 + ce9ee38 commit f6bd49b
Show file tree
Hide file tree
Showing 7 changed files with 40 additions and 5 deletions.
4 changes: 4 additions & 0 deletions src/decoder/Bridge.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ DecoderBridge::UpdateStreamTag(InputStream *is) noexcept
/* discard the song tag; we don't need it */
song_tag.reset();

if (stream_tag && tag && *stream_tag == *tag)
/* not changed */
return false;

stream_tag = std::move(tag);
return true;
}
Expand Down
12 changes: 7 additions & 5 deletions src/player/Thread.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -904,13 +904,15 @@ PlayerControl::LockUpdateSongTag(DetachedSong &song,
streams may change tags dynamically */
return;

song.SetTag(new_tag);
if (new_tag != song.GetTag()) {
song.SetTag(new_tag);

LockSetTaggedSong(song);
LockSetTaggedSong(song);

/* the main thread will update the playlist version when he
receives this event */
listener.OnPlayerTagModified();
/* the main thread will update the playlist version when he
receives this event */
listener.OnPlayerTagModified();
}
}

inline void
Expand Down
10 changes: 10 additions & 0 deletions src/tag/Item.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#define MPD_TAG_ITEM_HXX

#include <cstdint>
#include <cstring>

enum TagType : uint8_t;

Expand All @@ -22,6 +23,15 @@ struct TagItem {
*/
char value[1];

bool operator==(const TagItem &other) const noexcept {
return (this == &other) ? true :
type == other.type && std::strcmp(value, other.value) == 0;
}

private:
/* making the constructor private
to only allow construction by TagPoolItem. */
friend struct TagPoolItem;
TagItem() = default;
TagItem(const TagItem &other) = delete;
TagItem &operator=(const TagItem &other) = delete;
Expand Down
9 changes: 9 additions & 0 deletions src/tag/Tag.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@

#include <cassert>

bool
Tag::operator==(const Tag &other) const noexcept {
return (this == &other) ? true :
duration == other.duration
&& has_playlist == other.has_playlist
&& num_items == other.num_items
&& std::equal(begin(), end(), other.begin(), other.end());
}

void
Tag::Clear() noexcept
{
Expand Down
2 changes: 2 additions & 0 deletions src/tag/Tag.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,8 @@ struct Tag {
return *this;
}

bool operator==(const Tag &other) const noexcept;

/**
* Similar to the move operator, but move only the #TagItem
* array.
Expand Down
4 changes: 4 additions & 0 deletions src/util/DereferenceIterator.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ public:
return DereferenceIterator{original - n};
}

constexpr auto operator-(const DereferenceIterator<IT, VT>& other) const noexcept {
return std::distance(other.original, original);
}

/* this is a template to allow comparisons with sentinel end
iterators */
template<typename IT2>
Expand Down
4 changes: 4 additions & 0 deletions src/util/TerminatedArray.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ public:
return iterator{cursor - n};
}

constexpr auto operator-(const iterator& other) const noexcept {
return std::distance(other.cursor, cursor);
}

reference operator*() const noexcept {
return *cursor;
}
Expand Down

0 comments on commit f6bd49b

Please sign in to comment.