mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager
synced 2024-10-01 13:55:36 +00:00
glib-aux/trivial: rename arguments in nm_strv_cleanup() function
"skip_repeated" sounds as if the function would only drop duplicate elements that follow each other (in which case, the operation would be O(n)). But it does search the entire array to prevent duplicates (resulting in O(n^2)). Rename the argument "skip_repeated" to "no_duplicates" to make that clearer. Also, rename "skip_{empty,duplicates}" to "no_{empty,duplicates}". The function removes those elements from the list, so "skip" is a bit misleading too.
This commit is contained in:
parent
ce3de03d14
commit
07428acf9e
|
@ -2076,7 +2076,7 @@ nm_strv_is_same_unordered(const char *const *strv1,
|
|||
}
|
||||
|
||||
const char **
|
||||
nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated)
|
||||
nm_strv_cleanup_const(const char **strv, gboolean no_empty, gboolean no_duplicates)
|
||||
{
|
||||
gsize i;
|
||||
gsize j;
|
||||
|
@ -2084,12 +2084,12 @@ nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repe
|
|||
if (!strv || !*strv)
|
||||
return strv;
|
||||
|
||||
if (!skip_empty && !skip_repeated)
|
||||
if (!no_empty && !no_duplicates)
|
||||
return strv;
|
||||
|
||||
j = 0;
|
||||
for (i = 0; strv[i]; i++) {
|
||||
if ((skip_empty && !*strv[i]) || (skip_repeated && nm_strv_contains(strv, j, strv[i])))
|
||||
if ((no_empty && !*strv[i]) || (no_duplicates && nm_strv_contains(strv, j, strv[i])))
|
||||
continue;
|
||||
strv[j++] = strv[i];
|
||||
}
|
||||
|
@ -2098,7 +2098,7 @@ nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repe
|
|||
}
|
||||
|
||||
char **
|
||||
nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean skip_empty, gboolean skip_repeated)
|
||||
nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean no_empty, gboolean no_duplicates)
|
||||
{
|
||||
gsize i;
|
||||
gsize j;
|
||||
|
@ -2112,11 +2112,11 @@ nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean skip_empty, gbo
|
|||
for (i = 0; strv[i]; i++)
|
||||
g_strstrip(strv[i]);
|
||||
}
|
||||
if (!skip_empty && !skip_repeated)
|
||||
if (!no_empty && !no_duplicates)
|
||||
return strv;
|
||||
j = 0;
|
||||
for (i = 0; strv[i]; i++) {
|
||||
if ((skip_empty && !*strv[i]) || (skip_repeated && nm_strv_contains(strv, j, strv[i])))
|
||||
if ((no_empty && !*strv[i]) || (no_duplicates && nm_strv_contains(strv, j, strv[i])))
|
||||
g_free(strv[i]);
|
||||
else
|
||||
strv[j++] = strv[i];
|
||||
|
|
|
@ -529,12 +529,10 @@ gssize _nm_strv_find_first(const char *const *list, gssize len, const char *need
|
|||
|
||||
gboolean nm_strv_has_duplicate(const char *const *list, gssize len, gboolean is_sorted);
|
||||
|
||||
const char **nm_strv_cleanup_const(const char **strv, gboolean skip_empty, gboolean skip_repeated);
|
||||
const char **nm_strv_cleanup_const(const char **strv, gboolean no_empty, gboolean no_duplicates);
|
||||
|
||||
char **nm_strv_cleanup(char **strv,
|
||||
gboolean strip_whitespace,
|
||||
gboolean skip_empty,
|
||||
gboolean skip_repeated);
|
||||
char **
|
||||
nm_strv_cleanup(char **strv, gboolean strip_whitespace, gboolean no_empty, gboolean no_duplicates);
|
||||
|
||||
gboolean nm_strv_is_same_unordered(const char *const *strv1,
|
||||
gssize len1,
|
||||
|
|
Loading…
Reference in a new issue