diff options
author | Eric Wong <normalperson@yhbt.net> | 2008-10-12 03:35:45 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2008-10-12 05:27:34 -0700 |
commit | bb106c3bf8daf366a4b4ca7229010c038f89755c (patch) | |
tree | 2db77aeed63d095a5533fb6f5d175af4cb10dade /src/songvec.c | |
parent | d60f11020f4901b806c822ef5ab2d87bbb9e4077 (diff) | |
download | mpd-bb106c3bf8daf366a4b4ca7229010c038f89755c.tar.gz mpd-bb106c3bf8daf366a4b4ca7229010c038f89755c.tar.xz mpd-bb106c3bf8daf366a4b4ca7229010c038f89755c.zip |
directory: always maintain sorted properties vectors
This allows clients to see sorted results while we're
updating the DB and removes the need for us to have
to sort manually.
We'll have to write separate routines for managing stored
playlists with songvecs eventually; but that's for another day.
Diffstat (limited to '')
-rw-r--r-- | src/songvec.c | 15 |
1 files changed, 6 insertions, 9 deletions
diff --git a/src/songvec.c b/src/songvec.c index 3d512e917..1a9635044 100644 --- a/src/songvec.c +++ b/src/songvec.c @@ -17,13 +17,6 @@ static size_t sv_size(struct songvec *sv) return sv->nr * sizeof(struct mpd_song *); } -void songvec_sort(struct songvec *sv) -{ - pthread_mutex_lock(&nr_lock); - qsort(sv->base, sv->nr, sizeof(struct mpd_song *), songvec_cmp); - pthread_mutex_unlock(&nr_lock); -} - struct mpd_song *songvec_find(const struct songvec *sv, const char *url) { int i; @@ -68,10 +61,14 @@ int songvec_delete(struct songvec *sv, const struct mpd_song *del) void songvec_add(struct songvec *sv, struct mpd_song *add) { + size_t old_nr; + pthread_mutex_lock(&nr_lock); - ++sv->nr; + old_nr = sv->nr++; sv->base = xrealloc(sv->base, sv_size(sv)); - sv->base[sv->nr - 1] = add; + sv->base[old_nr] = add; + if (old_nr && songvec_cmp(&sv->base[old_nr - 1], &add) >= 0) + qsort(sv->base, sv->nr, sizeof(struct mpd_song *), songvec_cmp); pthread_mutex_unlock(&nr_lock); } |