aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMax Kellermann <max@duempel.org>2012-01-24 18:05:28 +0100
committerMax Kellermann <max@duempel.org>2012-01-24 18:06:52 +0100
commit5d5c753c746646b0fa86fd2395fb4f76fd96aaae (patch)
tree7b48c332b9b589ff6a52d173a1a62625e61cf9dc /src
parent7e7e3eb8d5686e11a126128ff43adf34a3ad8f90 (diff)
downloadmpd-5d5c753c746646b0fa86fd2395fb4f76fd96aaae.tar.gz
mpd-5d5c753c746646b0fa86fd2395fb4f76fd96aaae.tar.xz
mpd-5d5c753c746646b0fa86fd2395fb4f76fd96aaae.zip
songvec: move code to songvec_find_pointer()
Diffstat (limited to 'src')
-rw-r--r--src/songvec.c46
1 files changed, 28 insertions, 18 deletions
diff --git a/src/songvec.c b/src/songvec.c
index 5f5b43f08..9e0321583 100644
--- a/src/songvec.c
+++ b/src/songvec.c
@@ -142,30 +142,40 @@ songvec_find(const struct songvec *sv, const char *uri)
return ret;
}
+/**
+ * Determine the index of the specified #song inside the #songvec, and
+ * returns the index. The caller must hold the db_mutex.
+ */
+G_GNUC_PURE
+static size_t
+songvec_find_pointer(const struct songvec *sv, const struct song *song)
+{
+ for (size_t i = 0;; ++i) {
+ assert(i < sv->nr); /* the song must exist */
+
+ if (sv->base[i] == song)
+ return i;
+ }
+}
+
void
songvec_delete(struct songvec *sv, const struct song *del)
{
- size_t i;
-
db_lock();
- for (i = 0; i < sv->nr; ++i) {
- if (sv->base[i] != del)
- continue;
- /* we _don't_ call song_free() here */
- if (!--sv->nr) {
- g_free(sv->base);
- sv->base = NULL;
- } else {
- memmove(&sv->base[i], &sv->base[i + 1],
- (sv->nr - i) * sizeof(struct song *));
- sv->base = g_realloc(sv->base, sv_size(sv));
- }
- db_unlock();
- return;
+
+ const size_t i = songvec_find_pointer(sv, del);
+
+ /* we _don't_ call song_free() here */
+ if (!--sv->nr) {
+ g_free(sv->base);
+ sv->base = NULL;
+ } else {
+ memmove(&sv->base[i], &sv->base[i + 1],
+ (sv->nr - i) * sizeof(struct song *));
+ sv->base = g_realloc(sv->base, sv_size(sv));
}
- db_unlock();
- assert(false);
+ db_unlock();
}
void