diff options
Diffstat (limited to 'src/pulsecore/hashmap.c')
| -rw-r--r-- | src/pulsecore/hashmap.c | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/src/pulsecore/hashmap.c b/src/pulsecore/hashmap.c index c9d5632c..b7f4109b 100644 --- a/src/pulsecore/hashmap.c +++ b/src/pulsecore/hashmap.c @@ -1,5 +1,3 @@ -/* $Id$ */ - /*** This file is part of PulseAudio. @@ -191,24 +189,36 @@ unsigned pa_hashmap_size(pa_hashmap *h) { } void *pa_hashmap_iterate(pa_hashmap *h, void **state, const void **key) { + struct hashmap_entry *e; + pa_assert(h); pa_assert(state); - if (!*state) - *state = h->first_entry; + if (*state == (void*) -1) + goto at_end; + + if ((!*state && !h->first_entry)) + goto at_end; + + e = *state ? *state : h->first_entry; + + if (e->next) + *state = e->next; else - *state = ((struct hashmap_entry*) *state)->next; + *state = (void*) -1; - if (!*state) { - if (key) - *key = NULL; - return NULL; - } + if (key) + *key = e->key; + + return e->value; + +at_end: + *state = (void *) -1; if (key) - *key = ((struct hashmap_entry*) *state)->key; + *key = NULL; - return ((struct hashmap_entry*) *state)->value; + return NULL; } void* pa_hashmap_steal_first(pa_hashmap *h) { |
