diff options
author | Max Kellermann <max@duempel.org> | 2012-02-12 17:50:30 +0100 |
---|---|---|
committer | Max Kellermann <max@duempel.org> | 2012-02-12 17:50:30 +0100 |
commit | ac3ad452c03292e4c57b0d0e21c2dd407eb03a27 (patch) | |
tree | 10e12f06f7a62a0cab6eb0bf06a4e8a09e2d0d78 /src/playlist_vector.c | |
parent | 027c01511cfb8eac1a2e3f9fc54cfbb2bf968870 (diff) | |
download | mpd-ac3ad452c03292e4c57b0d0e21c2dd407eb03a27.tar.gz mpd-ac3ad452c03292e4c57b0d0e21c2dd407eb03a27.tar.xz mpd-ac3ad452c03292e4c57b0d0e21c2dd407eb03a27.zip |
playlist_vector: use the list_head library
Diffstat (limited to '')
-rw-r--r-- | src/playlist_vector.c | 55 |
1 files changed, 18 insertions, 37 deletions
diff --git a/src/playlist_vector.c b/src/playlist_vector.c index cfbe8939e..be418f8af 100644 --- a/src/playlist_vector.c +++ b/src/playlist_vector.c @@ -46,60 +46,43 @@ playlist_metadata_free(struct playlist_metadata *pm) } void -playlist_vector_deinit(struct playlist_vector *pv) +playlist_vector_deinit(struct list_head *pv) { assert(pv != NULL); - while (pv->head != NULL) { - struct playlist_metadata *pm = pv->head; - pv->head = pm->next; + struct playlist_metadata *pm, *n; + playlist_vector_for_each_safe(pm, n, pv) playlist_metadata_free(pm); - } } -static struct playlist_metadata ** -playlist_vector_find_p(struct playlist_vector *pv, const char *name) +struct playlist_metadata * +playlist_vector_find(struct list_head *pv, const char *name) { assert(pv != NULL); assert(name != NULL); - struct playlist_metadata **pmp = &pv->head; - - for (;;) { - struct playlist_metadata *pm = *pmp; - if (pm == NULL) - return NULL; - + struct playlist_metadata *pm; + playlist_vector_for_each(pm, pv) if (strcmp(pm->name, name) == 0) - return pmp; - - pmp = &pm->next; - } -} + return pm; -struct playlist_metadata * -playlist_vector_find(struct playlist_vector *pv, const char *name) -{ - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - return pmp != NULL ? *pmp : NULL; + return NULL; } void -playlist_vector_add(struct playlist_vector *pv, +playlist_vector_add(struct list_head *pv, const char *name, time_t mtime) { struct playlist_metadata *pm = playlist_metadata_new(name, mtime); - pm->next = pv->head; - pv->head = pm; + list_add(&pm->siblings, pv); } bool -playlist_vector_update_or_add(struct playlist_vector *pv, +playlist_vector_update_or_add(struct list_head *pv, const char *name, time_t mtime) { - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - if (pmp != NULL) { - struct playlist_metadata *pm = *pmp; + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm != NULL) { if (mtime == pm->mtime) return false; @@ -111,15 +94,13 @@ playlist_vector_update_or_add(struct playlist_vector *pv, } bool -playlist_vector_remove(struct playlist_vector *pv, const char *name) +playlist_vector_remove(struct list_head *pv, const char *name) { - struct playlist_metadata **pmp = playlist_vector_find_p(pv, name); - if (pmp == NULL) + struct playlist_metadata *pm = playlist_vector_find(pv, name); + if (pm == NULL) return false; - struct playlist_metadata *pm = *pmp; - *pmp = pm->next; - + list_del(&pm->siblings); playlist_metadata_free(pm); return true; } |