summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2019-05-20 17:08:35 +0200
committerThomas Haller <thaller@redhat.com>2019-06-13 09:44:23 +0200
commitc1f0c29c5240903ad7a3616d9c85b59b5c0fd330 (patch)
treeac3de52857b172772016cdef3110c7b5ad4df46d
parentc4660c10e8f29e91e766fde07628f668f4498ffc (diff)
downloadNetworkManager-c1f0c29c5240903ad7a3616d9c85b59b5c0fd330.tar.gz
settings: use nm_utils_g_slist_find_str() in update_specs()
NMSettings is complicated enough. We should try to move independent code out of it, so that there is only logic that is essential there. While at it, rework how we copy the GSList items. I don't like GSList as a data structure, but there really is no need to allocate a new list. Just unlink the list element and prepend it in the other list.
-rw-r--r--src/settings/nm-settings.c39
1 files changed, 15 insertions, 24 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c
index 0e7dfcd337..b0f37f62f3 100644
--- a/src/settings/nm-settings.c
+++ b/src/settings/nm-settings.c
@@ -535,18 +535,6 @@ nm_settings_get_unmanaged_specs (NMSettings *self)
return priv->unmanaged_specs;
}
-static gboolean
-find_spec (GSList *spec_list, const char *spec)
-{
- GSList *iter;
-
- for (iter = spec_list; iter; iter = g_slist_next (iter)) {
- if (!strcmp ((const char *) iter->data, spec))
- return TRUE;
- }
- return FALSE;
-}
-
static void
update_specs (NMSettings *self, GSList **specs_ptr,
GSList * (*get_specs_func) (NMSettingsPlugin *))
@@ -554,21 +542,24 @@ update_specs (NMSettings *self, GSList **specs_ptr,
NMSettingsPrivate *priv = NM_SETTINGS_GET_PRIVATE (self);
GSList *iter;
- g_slist_free_full (*specs_ptr, g_free);
- *specs_ptr = NULL;
+ g_slist_free_full (g_steal_pointer (specs_ptr), g_free);
for (iter = priv->plugins; iter; iter = g_slist_next (iter)) {
- GSList *specs, *specs_iter;
-
- specs = get_specs_func (NM_SETTINGS_PLUGIN (iter->data));
- for (specs_iter = specs; specs_iter; specs_iter = specs_iter->next) {
- if (!find_spec (*specs_ptr, (const char *) specs_iter->data)) {
- *specs_ptr = g_slist_prepend (*specs_ptr, specs_iter->data);
- } else
- g_free (specs_iter->data);
- }
+ GSList *specs;
- g_slist_free (specs);
+ specs = get_specs_func (iter->data);
+ while (specs) {
+ GSList *s = specs;
+
+ specs = g_slist_remove_link (specs, s);
+ if (nm_utils_g_slist_find_str (*specs_ptr, s->data)) {
+ g_free (s->data);
+ g_slist_free_1 (s);
+ continue;
+ }
+ s->next = *specs_ptr;
+ *specs_ptr = s;
+ }
}
}