diff options
author | Thomas Haller <thaller@redhat.com> | 2014-08-26 15:49:18 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2014-10-12 20:13:18 +0200 |
commit | 59f2c0fb3e9a7266ff39f4e1212024e9d845be75 (patch) | |
tree | 15cc93211baf639b2e55bb97a626e91af3bc9725 /src | |
parent | 91ec7dac90b3a8f0c45b4501b9e90027680a98e6 (diff) | |
download | NetworkManager-59f2c0fb3e9a7266ff39f4e1212024e9d845be75.tar.gz |
core/policy: refactor auto_activate_device() to use a GPtrArray
Next we want to sort the array, g_slist_sort() is not guaranteed to be
stable, while g_ptr_array_sort() is. Also, sorting a GSList has
worse performance.
Signed-off-by: Thomas Haller <thaller@redhat.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/nm-policy.c | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c index ca17ea0c8e..d20cf78ce5 100644 --- a/src/nm-policy.c +++ b/src/nm-policy.c @@ -42,6 +42,7 @@ #include "nm-firewall-manager.h" #include "nm-dispatcher.h" #include "nm-utils.h" +#include "nm-core-internal.h" #include "nm-glib-compat.h" #include "nm-manager.h" #include "nm-settings.h" @@ -990,7 +991,9 @@ auto_activate_device (gpointer user_data) NMPolicyPrivate *priv; NMConnection *best_connection; char *specific_object = NULL; - GSList *connections, *iter; + GPtrArray *connections; + GSList *connection_list; + guint i; g_assert (data); policy = data->policy; @@ -1005,12 +1008,17 @@ auto_activate_device (gpointer user_data) if (nm_device_get_act_request (data->device)) goto out; - connections = nm_manager_get_activatable_connections (priv->manager); + connection_list = nm_manager_get_activatable_connections (priv->manager); + if (!connection_list) + goto out; + + connections = _nm_utils_copy_slist_to_array (connection_list, NULL, NULL); + g_slist_free (connection_list); /* Find the first connection that should be auto-activated */ best_connection = NULL; - for (iter = connections; iter; iter = g_slist_next (iter)) { - NMSettingsConnection *candidate = NM_SETTINGS_CONNECTION (iter->data); + for (i = 0; i < connections->len; i++) { + NMSettingsConnection *candidate = NM_SETTINGS_CONNECTION (connections->pdata[i]); if (!nm_settings_connection_can_autoconnect (candidate)) continue; @@ -1019,7 +1027,7 @@ auto_activate_device (gpointer user_data) break; } } - g_slist_free (connections); + g_ptr_array_free (connections, TRUE); if (best_connection) { GError *error = NULL; |