playlist: make kept song count collision resistant

This commit is contained in:
Andrzej Rybczak
2014-08-30 02:30:54 +02:00
parent d20765c53a
commit dcaa1cafa4
8 changed files with 37 additions and 38 deletions

View File

@@ -360,20 +360,20 @@ unsigned Playlist::currentSongLength() const
bool Playlist::checkForSong(const MPD::Song &s)
{
return m_song_hashes.find(s.getHash()) != m_song_hashes.end();
return m_song_refs.find(s) != m_song_refs.end();
}
void Playlist::registerHash(size_t hash)
void Playlist::registerSong(const MPD::Song &s)
{
++m_song_hashes[hash];
++m_song_refs[s];
}
void Playlist::unregisterHash(size_t hash)
void Playlist::unregisterSong(const MPD::Song &s)
{
auto it = m_song_hashes.find(hash);
assert(it != m_song_hashes.end());
auto it = m_song_refs.find(s);
assert(it != m_song_refs.end());
if (it->second == 1)
m_song_hashes.erase(it);
m_song_refs.erase(it);
else
--it->second;
}