summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2014-08-26 15:49:18 +0200
committerThomas Haller <thaller@redhat.com>2014-08-26 16:40:31 +0200
commit259ee74c3e0a9583d54b6096a037d0b91b02fe71 (patch)
tree32c0b1c46eb8016f74f0897eea63546571bb3cc4
parent5effcbdf5b3d001490bb2aba0f8c715dcce2cb43 (diff)
downloadNetworkManager-259ee74c3e0a9583d54b6096a037d0b91b02fe71.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>
-rw-r--r--src/nm-policy.c18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/nm-policy.c b/src/nm-policy.c
index 09323e72b0..7964d1d3e7 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_slist_to_ptr_array (connection_list);
+ 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;