From c7689d72d69330b3bb68dbbeb151b8762ea1f9fa Mon Sep 17 00:00:00 2001 From: Andrzej Rybczak Date: Thu, 12 Mar 2009 21:26:56 +0100 Subject: [PATCH] improve playlist updating the case when sizes of mpd's and ncmpcpp's are equal is redundant. what is more, it caused unneded overhead, because it was comparing whole playlists. plchanges commands returns only songs that have really changed, so this piece of code was simply wrong. --- src/status.cpp | 68 +++++++++++++++++++------------------------------- 1 file changed, 26 insertions(+), 42 deletions(-) diff --git a/src/status.cpp b/src/status.cpp index 8fdf29e7..ba00fa7f 100644 --- a/src/status.cpp +++ b/src/status.cpp @@ -190,54 +190,38 @@ void NcmpcppStatusChanged(Connection *Mpd, StatusChanges changed, void *) myPlaylist->Main()->ShowAll(); SongList list; size_t playlist_length = Mpd->GetPlaylistLength(); - if (playlist_length != myPlaylist->Main()->Size()) + + if (playlist_length < myPlaylist->Main()->Size()) { - if (playlist_length < myPlaylist->Main()->Size()) - { - myPlaylist->Main()->Clear(playlist_length < myPlaylist->Main()->GetHeight() && myScreen == myPlaylist); - Mpd->GetPlaylistChanges(-1, list); - } - else - Mpd->GetPlaylistChanges(Mpd->GetOldPlaylistID(), list); - - myPlaylist->Main()->Reserve(playlist_length); - for (SongList::const_iterator it = list.begin(); it != list.end(); it++) - { - int pos = (*it)->GetPosition(); - if (pos < int(myPlaylist->Main()->Size())) - { - // if song's already in playlist, replace it with a new one - myPlaylist->Main()->at(pos) = **it; - } - else - { - // otherwise just add it to playlist - myPlaylist->Main()->AddOption(**it, myPlaylist->NowPlaying == pos); - } - myPlaylist->Main()->at(pos).CopyPtr(0); - (*it)->NullMe(); - } - - if (myScreen == myPlaylist) - { - if (!playlist_length || myPlaylist->Main()->Size() < myPlaylist->Main()->GetHeight()) - myPlaylist->Main()->Window::Clear(); - myPlaylist->Main()->Refresh(); - } + myPlaylist->Main()->Clear(playlist_length < myPlaylist->Main()->GetHeight() && myScreen == myPlaylist); + Mpd->GetPlaylistChanges(-1, list); } else + Mpd->GetPlaylistChanges(Mpd->GetOldPlaylistID(), list); + + myPlaylist->Main()->Reserve(playlist_length); + for (SongList::const_iterator it = list.begin(); it != list.end(); it++) { - Mpd->GetPlaylistChanges(-1, list); - - for (size_t i = 0; i < myPlaylist->Main()->Size(); i++) + int pos = (*it)->GetPosition(); + if (pos < int(myPlaylist->Main()->Size())) { - if (*list[i] != myPlaylist->Main()->at(i)) - { - myPlaylist->Main()->at(i) = *list[i]; - myPlaylist->Main()->at(i).CopyPtr(0); - list[i]->NullMe(); - } + // if song's already in playlist, replace it with a new one + myPlaylist->Main()->at(pos) = **it; } + else + { + // otherwise just add it to playlist + myPlaylist->Main()->AddOption(**it, myPlaylist->NowPlaying == pos); + } + myPlaylist->Main()->at(pos).CopyPtr(0); + (*it)->NullMe(); + } + + if (myScreen == myPlaylist) + { + if (!playlist_length || myPlaylist->Main()->Size() < myPlaylist->Main()->GetHeight()) + myPlaylist->Main()->Window::Clear(); + myPlaylist->Main()->Refresh(); } if (was_filtered) myPlaylist->ApplyFilter(myPlaylist->Main()->GetFilter());