libsaria: Fix playlist bulk insert

My "insert while sorted" code was getting complicated, and didn't send
all the notifications to the UI (only the first ~1200 songs were
displayed).  This patch both simplifies the code and produces the right
answer without a noticable performance penalty.

Signed-off-by: Bryan Schumaker <bjschuma@gmail.com>
This commit is contained in:
Bryan Schumaker 2012-11-03 17:32:26 -04:00
parent d345d3211f
commit e116025754
2 changed files with 7 additions and 26 deletions

View File

@ -49,7 +49,6 @@ namespace libsaria
protected:
vector<Track *> plist;
void add_sorted(list<Track *> &);
public:
Playlist(unsigned int);

View File

@ -63,24 +63,6 @@ namespace libsaria
remove_index(*it);
}
void Playlist::add_sorted(list<Track *> &tracks)
{
list<Track *>::iterator it;
tracks.sort(compare_tracks);
plist.insert(plist.end(), tracks.begin(), tracks.end());
do_sort();
it = tracks.begin();
for (unsigned i = 0; i < plist.size(); i++) {
if (plist[i] == *it) {
add_track(*it, i);
if (it++ == tracks.end())
break;
}
}
}
void Playlist::push_front(Track *track)
{
unsigned int index = 0;
@ -108,14 +90,14 @@ namespace libsaria
void Playlist::push_back(list<Track *> &tracks)
{
list<Track *>::iterator it;
for (it = tracks.begin(); it != tracks.end(); it++) {
plist.push_back(*it);
add_track(*it, plist.size());
}
if (get_sorted())
add_sorted(tracks);
else {
for (it = tracks.begin(); it != tracks.end(); it++)
push_back(*it);
if (plist.size() == tracks.size())
cur = 0;
if (get_sorted()) {
do_sort();
notify_update_all();
}
}