pulseaudio/0001-idxset-Add-set-contains-function.patch

59 lines
1.9 KiB
Diff
Raw Normal View History

From fb63e589310fab20e60c46bb40c7b7acab5eeac9 Mon Sep 17 00:00:00 2001
From: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Date: Sat, 26 Jun 2021 12:05:17 +0300
Subject: [PATCH] idxset: Add set contains() function
This is functionally equivalent to get_by_data(s, p, NULL) == p, but
with a more obvious name and form because some existing code is instead
manually iterating through idxsets to check for existence of an item.
Signed-off-by: Alper Nebi Yasak <alpernebiyasak@gmail.com>
Part-of: <https://gitlab.freedesktop.org/pulseaudio/pulseaudio/-/merge_requests/596>
---
src/pulsecore/idxset.c | 14 ++++++++++++++
src/pulsecore/idxset.h | 3 +++
2 files changed, 17 insertions(+)
diff --git a/src/pulsecore/idxset.c b/src/pulsecore/idxset.c
index 5175ca217..91ac6a015 100644
--- a/src/pulsecore/idxset.c
+++ b/src/pulsecore/idxset.c
@@ -258,6 +258,20 @@ void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx) {
return e->data;
}
+bool pa_idxset_contains(pa_idxset *s, const void *p) {
+ unsigned hash;
+ struct idxset_entry *e;
+
+ pa_assert(s);
+
+ hash = s->hash_func(p) % NBUCKETS;
+
+ if (!(e = data_scan(s, hash, p)))
+ return false;
+
+ return e->data == p;
+}
+
void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx) {
struct idxset_entry *e;
unsigned hash;
diff --git a/src/pulsecore/idxset.h b/src/pulsecore/idxset.h
index 7acb202ff..6797852b7 100644
--- a/src/pulsecore/idxset.h
+++ b/src/pulsecore/idxset.h
@@ -66,6 +66,9 @@ void* pa_idxset_get_by_index(pa_idxset*s, uint32_t idx);
/* Get the entry by its data. The index is returned in *idx */
void* pa_idxset_get_by_data(pa_idxset*s, const void *p, uint32_t *idx);
+/* Return true if item is in idxset */
+bool pa_idxset_contains(pa_idxset *s, const void *p);
+
/* Similar to pa_idxset_get_by_index(), but removes the entry from the idxset. */
void* pa_idxset_remove_by_index(pa_idxset*s, uint32_t idx);
--
2.33.0