Song: pass reference to song_equals()

This commit is contained in:
Max Kellermann 2013-10-21 23:19:15 +02:00
parent f6d67ac260
commit 20cba9e89f
5 changed files with 14 additions and 19 deletions

View File

@ -47,10 +47,8 @@ decoder_control::~decoder_control()
} }
bool bool
decoder_control::IsCurrentSong(const Song *_song) const decoder_control::IsCurrentSong(const Song &_song) const
{ {
assert(_song != nullptr);
switch (state) { switch (state) {
case DecoderState::STOP: case DecoderState::STOP:
case DecoderState::ERROR: case DecoderState::ERROR:
@ -58,7 +56,7 @@ decoder_control::IsCurrentSong(const Song *_song) const
case DecoderState::START: case DecoderState::START:
case DecoderState::DECODE: case DecoderState::DECODE:
return song_equals(song, _song); return SongEquals(*song, _song);
} }
assert(false); assert(false);

View File

@ -274,10 +274,10 @@ struct decoder_control {
* Caller must lock the object. * Caller must lock the object.
*/ */
gcc_pure gcc_pure
bool IsCurrentSong(const Song *_song) const; bool IsCurrentSong(const Song &_song) const;
gcc_pure gcc_pure
bool LockIsCurrentSong(const Song *_song) const { bool LockIsCurrentSong(const Song &_song) const {
Lock(); Lock();
const bool result = IsCurrentSong(_song); const bool result = IsCurrentSong(_song);
Unlock(); Unlock();

View File

@ -521,7 +521,7 @@ Player::SeekDecoder()
const unsigned start_ms = pc.next_song->start_ms; const unsigned start_ms = pc.next_song->start_ms;
if (!dc.LockIsCurrentSong(pc.next_song)) { if (!dc.LockIsCurrentSong(*pc.next_song)) {
/* the decoder is already decoding the "next" song - /* the decoder is already decoding the "next" song -
stop it and start the previous song again */ stop it and start the previous song again */

View File

@ -127,23 +127,20 @@ directory_is_same(const Directory *a, const Directory *b)
} }
bool bool
song_equals(const Song *a, const Song *b) SongEquals(const Song &a, const Song &b)
{ {
assert(a != nullptr); if (a.parent != nullptr && b.parent != nullptr &&
assert(b != nullptr); !directory_equals(*a.parent, *b.parent) &&
(a.parent == &detached_root || b.parent == &detached_root)) {
if (a->parent != nullptr && b->parent != nullptr &&
!directory_equals(*a->parent, *b->parent) &&
(a->parent == &detached_root || b->parent == &detached_root)) {
/* must compare the full URI if one of the objects is /* must compare the full URI if one of the objects is
"detached" */ "detached" */
const auto au = a->GetURI(); const auto au = a.GetURI();
const auto bu = b->GetURI(); const auto bu = b.GetURI();
return au == bu; return au == bu;
} }
return directory_is_same(a->parent, b->parent) && return directory_is_same(a.parent, b.parent) &&
strcmp(a->uri, b->uri) == 0; strcmp(a.uri, b.uri) == 0;
} }
std::string std::string

View File

@ -145,6 +145,6 @@ struct Song {
*/ */
gcc_pure gcc_pure
bool bool
song_equals(const Song *a, const Song *b); SongEquals(const Song &a, const Song &b);
#endif #endif