From ca869bff9f79025362cc7a55c5ebdc8e8cf10424 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 15 Mar 2021 14:41:11 +0100 Subject: [PATCH] shared: add nm_utils_strv_find_binary_search() helper --- src/libnm-glib-aux/nm-shared-utils.h | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h index e28a6f825e..db816a8c10 100644 --- a/src/libnm-glib-aux/nm-shared-utils.h +++ b/src/libnm-glib-aux/nm-shared-utils.h @@ -2020,6 +2020,24 @@ gssize nm_utils_ptrarray_find_binary_search(gconstpointer * list, gssize * out_idx_first, gssize * out_idx_last); +#define nm_utils_strv_find_binary_search(strv, len, needle) \ + ({ \ + const char *const *const _strv = NM_CAST_STRV_CC(strv); \ + const gsize _len = (len); \ + const char *const _needle = (needle); \ + \ + nm_assert(_len == 0 || _strv); \ + nm_assert(_needle); \ + \ + nm_utils_ptrarray_find_binary_search((gconstpointer *) _strv, \ + _len, \ + _needle, \ + nm_strcmp_with_data, \ + NULL, \ + NULL, \ + NULL); \ + }) + gssize nm_utils_array_find_binary_search(gconstpointer list, gsize elem_size, gsize len,