mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-14 23:50:29 +01:00
glib-aux: move nm_utils_ptrarray_find_first() helper to libnm-glib-aux
This commit is contained in:
parent
a016f24353
commit
af0cfc559b
6 changed files with 34 additions and 32 deletions
|
|
@ -6000,7 +6000,7 @@ delayed_action_handle_one(NMPlatform *platform)
|
|||
g_ptr_array_remove_index_fast(priv->delayed_action.list_master_connected, 0);
|
||||
if (priv->delayed_action.list_master_connected->len == 0)
|
||||
priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_MASTER_CONNECTED;
|
||||
nm_assert(_nm_utils_ptrarray_find_first(
|
||||
nm_assert(nm_utils_ptrarray_find_first(
|
||||
(gconstpointer *) priv->delayed_action.list_master_connected->pdata,
|
||||
priv->delayed_action.list_master_connected->len,
|
||||
user_data)
|
||||
|
|
@ -6044,7 +6044,7 @@ delayed_action_handle_one(NMPlatform *platform)
|
|||
g_ptr_array_remove_index_fast(priv->delayed_action.list_refresh_link, 0);
|
||||
if (priv->delayed_action.list_refresh_link->len == 0)
|
||||
priv->delayed_action.flags &= ~DELAYED_ACTION_TYPE_REFRESH_LINK;
|
||||
nm_assert(_nm_utils_ptrarray_find_first(
|
||||
nm_assert(nm_utils_ptrarray_find_first(
|
||||
(gconstpointer *) priv->delayed_action.list_refresh_link->pdata,
|
||||
priv->delayed_action.list_refresh_link->len,
|
||||
user_data)
|
||||
|
|
@ -6097,7 +6097,7 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo
|
|||
|
||||
switch (action_type) {
|
||||
case DELAYED_ACTION_TYPE_REFRESH_LINK:
|
||||
if (_nm_utils_ptrarray_find_first(
|
||||
if (nm_utils_ptrarray_find_first(
|
||||
(gconstpointer *) priv->delayed_action.list_refresh_link->pdata,
|
||||
priv->delayed_action.list_refresh_link->len,
|
||||
user_data)
|
||||
|
|
@ -6105,7 +6105,7 @@ delayed_action_schedule(NMPlatform *platform, DelayedActionType action_type, gpo
|
|||
g_ptr_array_add(priv->delayed_action.list_refresh_link, user_data);
|
||||
break;
|
||||
case DELAYED_ACTION_TYPE_MASTER_CONNECTED:
|
||||
if (_nm_utils_ptrarray_find_first(
|
||||
if (nm_utils_ptrarray_find_first(
|
||||
(gconstpointer *) priv->delayed_action.list_master_connected->pdata,
|
||||
priv->delayed_action.list_master_connected->len,
|
||||
user_data)
|
||||
|
|
|
|||
|
|
@ -824,30 +824,6 @@ _nm_utils_copy_object_array(const GPtrArray *array)
|
|||
return _nm_utils_copy_array(array, g_object_ref, g_object_unref);
|
||||
}
|
||||
|
||||
gssize
|
||||
_nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle)
|
||||
{
|
||||
gssize i;
|
||||
|
||||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
if (len > 0) {
|
||||
g_return_val_if_fail(list, -1);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
g_return_val_if_fail(needle, -1);
|
||||
for (i = 0; list && list[i]; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
void
|
||||
_nm_utils_bytes_from_dbus(GVariant *dbus_value, GValue *prop_value)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -8618,7 +8618,7 @@ _test_find_binary_search_do(const int *array, gsize len)
|
|||
for (i = 0; i < len; i++)
|
||||
parray[i] = GINT_TO_POINTER(array[i]);
|
||||
|
||||
expected_result = _nm_utils_ptrarray_find_first(parray, len, pneedle);
|
||||
expected_result = nm_utils_ptrarray_find_first(parray, len, pneedle);
|
||||
|
||||
idx = nm_utils_ptrarray_find_binary_search(parray,
|
||||
len,
|
||||
|
|
@ -8795,7 +8795,7 @@ test_nm_utils_ptrarray_find_binary_search_with_duplicates(void)
|
|||
&idx_first,
|
||||
&idx_last);
|
||||
|
||||
idx_first2 = _nm_utils_ptrarray_find_first(arr, i_len, p);
|
||||
idx_first2 = nm_utils_ptrarray_find_first(arr, i_len, p);
|
||||
|
||||
idx2 = nm_utils_array_find_binary_search(arr,
|
||||
sizeof(gpointer),
|
||||
|
|
|
|||
|
|
@ -412,8 +412,6 @@ GPtrArray *
|
|||
_nm_utils_copy_array(const GPtrArray *array, NMUtilsCopyFunc copy_func, GDestroyNotify free_func);
|
||||
GPtrArray *_nm_utils_copy_object_array(const GPtrArray *array);
|
||||
|
||||
gssize _nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle);
|
||||
|
||||
GSList *_nm_utils_strv_to_slist(char **strv, gboolean deep_copy);
|
||||
char ** _nm_utils_slist_to_strv(const GSList *slist, gboolean deep_copy);
|
||||
|
||||
|
|
|
|||
|
|
@ -3801,6 +3801,32 @@ _nm_utils_strv_dup_packed(const char *const *strv, gssize len)
|
|||
|
||||
/*****************************************************************************/
|
||||
|
||||
gssize
|
||||
nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle)
|
||||
{
|
||||
gssize i;
|
||||
|
||||
if (len == 0)
|
||||
return -1;
|
||||
|
||||
if (len > 0) {
|
||||
g_return_val_if_fail(list, -1);
|
||||
for (i = 0; i < len; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
} else {
|
||||
g_return_val_if_fail(needle, -1);
|
||||
for (i = 0; list && list[i]; i++) {
|
||||
if (list[i] == needle)
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
gssize
|
||||
nm_utils_ptrarray_find_binary_search(gconstpointer * list,
|
||||
gsize len,
|
||||
|
|
|
|||
|
|
@ -2027,6 +2027,8 @@ gssize nm_utils_array_find_binary_search(gconstpointer list,
|
|||
GCompareDataFunc cmpfcn,
|
||||
gpointer user_data);
|
||||
|
||||
gssize nm_utils_ptrarray_find_first(gconstpointer *list, gssize len, gconstpointer needle);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
void _nm_utils_strv_sort(const char **strv, gssize len);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue