improve 'Crop' function

deleting by songid seems to be very slow
in current mpd-git so use positions instead.
This commit is contained in:
Andrzej Rybczak
2009-02-16 15:25:23 +01:00
parent 34feba8d67
commit 2ec7748acd

View File

@@ -1402,10 +1402,10 @@ int main(int argc, char *argv[])
{ {
if (myPlaylist->Main()->hasSelected()) if (myPlaylist->Main()->hasSelected())
{ {
for (size_t i = 0; i < myPlaylist->Main()->Size(); i++) for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
{ {
if (!myPlaylist->Main()->isSelected(i) && i != size_t(myPlaylist->NowPlaying)) if (!myPlaylist->Main()->isSelected(i) && i != myPlaylist->NowPlaying)
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID()); Mpd->QueueDeleteSong(i);
} }
// if mpd deletes now playing song deletion will be sluggishly slow // if mpd deletes now playing song deletion will be sluggishly slow
// then so we have to assure it will be deleted at the very end. // then so we have to assure it will be deleted at the very end.
@@ -1423,10 +1423,9 @@ int main(int argc, char *argv[])
ShowMessage("Nothing is playing now!"); ShowMessage("Nothing is playing now!");
continue; continue;
} }
for (int i = 0; i < myPlaylist->NowPlaying; i++) for (int i = myPlaylist->Main()->Size()-1; i >= 0; i--)
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID()); if (i != myPlaylist->NowPlaying)
for (size_t i = myPlaylist->NowPlaying+1; i < myPlaylist->Main()->Size(); i++) Mpd->QueueDeleteSong(i);
Mpd->QueueDeleteSongId(myPlaylist->Main()->at(i).GetID());
ShowMessage("Deleting all items except now playing one..."); ShowMessage("Deleting all items except now playing one...");
Mpd->CommitQueue(); Mpd->CommitQueue();
ShowMessage("Items deleted!"); ShowMessage("Items deleted!");