diff options
author | Thomas Haller <thaller@redhat.com> | 2019-05-20 17:08:35 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2019-06-13 16:10:53 +0200 |
commit | ca1fe95ce0aac9b19a7e6c16fcf52b4046370eb0 (patch) | |
tree | 791757f1b275ac3a3b44a2663d83956383519f3e | |
parent | d7056d13d0f63187ae1081bbe356d23e8f2585f2 (diff) | |
download | NetworkManager-ca1fe95ce0aac9b19a7e6c16fcf52b4046370eb0.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.c | 39 |
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; + } } } |