From e0fc8a11d5310303e680f101604291a4139317dd Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 1 Aug 2022 20:44:08 +0200 Subject: [PATCH] glib-aux: add nm_g_hash_table_contains_any() helper --- src/libnm-glib-aux/nm-shared-utils.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index d8ec065732..3decea9b37 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -2405,6 +2405,25 @@ nm_g_hash_table_contains(GHashTable *hash, gconstpointer key) return hash ? g_hash_table_contains(hash, key) : FALSE; } +#define nm_g_hash_table_contains_any(hash, ...) \ + ({ \ + GHashTable *const _hash = (hash); \ + gconstpointer const _keys[] = {__VA_ARGS__}; \ + int _i_key; \ + gboolean _contains = FALSE; \ + \ + if (_hash) { \ + for (_i_key = 0; _i_key < (int) G_N_ELEMENTS(_keys); _i_key++) { \ + if (g_hash_table_contains(_hash, _keys[_i_key])) { \ + _contains = TRUE; \ + break; \ + } \ + } \ + } \ + \ + _contains; \ + }) + static inline gboolean nm_g_hash_table_remove(GHashTable *hash, gconstpointer key) {