if (template) {
s = pa_xnewdup(pa_alsa_setting, template, 1);
- s->options = pa_idxset_copy(template->options);
+ s->options = pa_idxset_copy(template->options, NULL);
s->name = pa_sprintf_malloc("%s+%s", template->name, o->name);
s->description =
(template->description[0] && o->description[0])
static pa_idxset* sink_get_formats(pa_sink *s) {
struct userdata *u = s->userdata;
- pa_idxset *ret = pa_idxset_new(NULL, NULL);
- pa_format_info *f;
- uint32_t idx;
pa_assert(u);
- PA_IDXSET_FOREACH(f, u->formats, idx) {
- pa_idxset_put(ret, pa_format_info_copy(f), NULL);
- }
-
- return ret;
+ return pa_idxset_copy(u->formats, (pa_copy_func_t) pa_format_info_copy);
}
static bool sink_set_formats(pa_sink *s, pa_idxset *formats) {
return s->n_entries == 0;
}
-pa_idxset *pa_idxset_copy(pa_idxset *s) {
+pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func) {
pa_idxset *copy;
struct idxset_entry *i;
copy = pa_idxset_new(s->hash_func, s->compare_func);
for (i = s->iterate_list_head; i; i = i->iterate_next)
- pa_idxset_put(copy, i->data, NULL);
+ pa_idxset_put(copy, copy_func ? copy_func(i->data) : i->data, NULL);
return copy;
}
typedef unsigned (*pa_hash_func_t)(const void *p);
typedef int (*pa_compare_func_t)(const void *a, const void *b);
+typedef void *(*pa_copy_func_t)(const void *p);
typedef struct pa_idxset pa_idxset;
/* Return true of the idxset is empty */
bool pa_idxset_isempty(pa_idxset *s);
-/* Duplicate the idxset. This will not copy the actual indexes */
-pa_idxset *pa_idxset_copy(pa_idxset *s);
+/* Duplicate the idxset. This will not copy the actual indexes. If copy_func is
+ * set, each entry is copied using the provided function, otherwise a shallow
+ * copy will be made. */
+pa_idxset *pa_idxset_copy(pa_idxset *s, pa_copy_func_t copy_func);
/* A macro to ease iteration through all entries */
#define PA_IDXSET_FOREACH(e, s, idx) \