summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2023-10-19 17:11:04 +0200
committerThomas Haller <thaller@redhat.com>2023-10-23 10:09:12 +0200
commit3cb10bdd1e9fba6a8a8148a0583b1332303aeeac (patch)
treefc2eba5b8d9376200409afd6a76a63ba5c89d2b0
parent5cd0fdb2dd6b885364ce044d7e0fa7d10a9fcf7c (diff)
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.
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.c12
-rw-r--r--src/libnm-glib-aux/nm-shared-utils.h8
2 files changed, 9 insertions, 11 deletions
diff --git a/src/libnm-glib-aux/nm-shared-utils.c b/src/libnm-glib-aux/nm-shared-utils.c
index 05b6750323..7e04b690a3 100644
--- a/src/libnm-glib-aux/nm-shared-utils.c
+++ b/src/libnm-glib-aux/nm-shared-utils.c
@@ -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];
diff --git a/src/libnm-glib-aux/nm-shared-utils.h b/src/libnm-glib-aux/nm-shared-utils.h
index 2a2312fb90..941b7fd986 100644
--- a/src/libnm-glib-aux/nm-shared-utils.h
+++ b/src/libnm-glib-aux/nm-shared-utils.h
@@ -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,