mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-11 05:10:22 +01:00
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.
This commit is contained in:
parent
d7056d13d0
commit
ca1fe95ce0
1 changed files with 14 additions and 23 deletions
|
|
@ -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;
|
||||
GSList *specs;
|
||||
|
||||
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);
|
||||
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;
|
||||
}
|
||||
|
||||
g_slist_free (specs);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue