hashmap: Add the ability to free keys

Since the hashmap stores a pointer to the key provided at pa_hashmap_put()
time, it make sense to allow the hashmap to be given ownership of the key and
have it free it at pa_hashmap_remove/free time.

To do this cleanly, we now provide the key and value free functions at hashmap
creation time with a pa_hashmap_new_full. With this, we do away with the free
function that was provided at remove/free time for freeing the value.
This commit is contained in:
Arun Raghavan 2013-09-14 11:50:10 +05:30
parent 317b46b571
commit 6825df8cec
41 changed files with 232 additions and 205 deletions

View file

@ -73,7 +73,7 @@ pa_source_new_data* pa_source_new_data_init(pa_source_new_data *data) {
pa_zero(*data);
data->proplist = pa_proplist_new();
data->ports = pa_hashmap_new(pa_idxset_string_hash_func, pa_idxset_string_compare_func);
data->ports = pa_hashmap_new_full(pa_idxset_string_hash_func, pa_idxset_string_compare_func, NULL, (pa_free_cb_t) pa_device_port_unref);
return data;
}
@ -133,7 +133,7 @@ void pa_source_new_data_done(pa_source_new_data *data) {
pa_proplist_free(data->proplist);
if (data->ports)
pa_hashmap_free(data->ports, (pa_free_cb_t) pa_device_port_unref);
pa_hashmap_free(data->ports);
pa_xfree(data->name);
pa_xfree(data->active_port);
@ -313,7 +313,8 @@ pa_source* pa_source_new(
0);
s->thread_info.rtpoll = NULL;
s->thread_info.outputs = pa_hashmap_new(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func);
s->thread_info.outputs = pa_hashmap_new_full(pa_idxset_trivial_hash_func, pa_idxset_trivial_compare_func, NULL,
(pa_free_cb_t) pa_source_output_unref);
s->thread_info.soft_volume = s->soft_volume;
s->thread_info.soft_muted = s->muted;
s->thread_info.state = s->state;
@ -660,7 +661,7 @@ static void source_free(pa_object *o) {
pa_log_info("Freeing source %u \"%s\"", s->index, s->name);
pa_idxset_free(s->outputs, NULL);
pa_hashmap_free(s->thread_info.outputs, (pa_free_cb_t) pa_source_output_unref);
pa_hashmap_free(s->thread_info.outputs);
if (s->silence.memblock)
pa_memblock_unref(s->silence.memblock);
@ -672,7 +673,7 @@ static void source_free(pa_object *o) {
pa_proplist_free(s->proplist);
if (s->ports)
pa_hashmap_free(s->ports, (pa_free_cb_t) pa_device_port_unref);
pa_hashmap_free(s->ports);
pa_xfree(s);
}