diff --git a/src/song.cpp b/src/song.cpp index 9b8479d1..9b23dbab 100644 --- a/src/song.cpp +++ b/src/song.cpp @@ -21,6 +21,7 @@ #include #include #include +#include #include #include #include @@ -32,12 +33,11 @@ namespace { -size_t calc_hash(const char* s, unsigned seed = 0) +size_t calc_hash(const char *s, size_t seed = 0) { - size_t hash = seed; - while (*s) - hash = hash * 101 + *s++; - return hash; + for (; *s != '\0'; ++s) + boost::hash_combine(seed, *s); + return seed; } } diff --git a/src/song.h b/src/song.h index c7bed84e..a649bf35 100644 --- a/src/song.h +++ b/src/song.h @@ -46,7 +46,8 @@ struct Song Song(const Song &rhs) : m_song(rhs.m_song), m_hash(rhs.m_hash) { } Song(Song &&rhs) : m_song(std::move(rhs.m_song)), m_hash(rhs.m_hash) { } - Song &operator=(Song rhs) { + Song &operator=(Song rhs) + { m_song = std::move(rhs.m_song); m_hash = rhs.m_hash; return *this; @@ -85,15 +86,15 @@ struct Song virtual bool empty() const; - bool operator==(const Song &rhs) const { + bool operator==(const Song &rhs) const + { if (m_hash != rhs.m_hash) return false; return strcmp(c_uri(), rhs.c_uri()) == 0; } - bool operator!=(const Song &rhs) const { - if (m_hash != rhs.m_hash) - return true; - return strcmp(c_uri(), rhs.c_uri()) != 0; + bool operator!=(const Song &rhs) const + { + return !(operator==(rhs)); } const char *c_uri() const { return m_song ? mpd_song_get_uri(m_song.get()) : ""; }