diff options
| author | Thomas Haller <thaller@redhat.com> | 2017-02-03 14:15:16 +0100 |
|---|---|---|
| committer | Thomas Haller <thaller@redhat.com> | 2017-02-10 14:43:24 +0100 |
| commit | 0861f47a1c5d277188c31d3f5275755f830b0765 (patch) | |
| tree | 5310bc142adad555fa843c2345408b5c94b35c22 /src/nm-checkpoint.c | |
| parent | da072ff008feea85fc78d47b237341a3ce7dcda6 (diff) | |
| download | NetworkManager-0861f47a1c5d277188c31d3f5275755f830b0765.tar.gz | |
core: refactor nm_settings_get_connections_sorted() to return array instead of GSList
We call these functions a lot. A GSList is just the wrong tool for the
job. Refactor the code to use instead a sorted array everywhere.
This means, we malloc() one array for all connections instead
slice-allocate a GSList item for each. Also, sorting an array
is faster then sorting a GSList.
Technically, the GSList implementation had the same big-O runtime
complexity, but using an array is still faster. That is, sorting
an array and a GSList is both O(n*log(n)).
Actually, nm_settings_get_connections_sorted() used
g_slist_insert_sorted() instead of g_slist_sort(). That results
in O(n^2). That could have been fixed to have O(n*log(n)), but
instead refactor the code to use an array.
Diffstat (limited to 'src/nm-checkpoint.c')
| -rw-r--r-- | src/nm-checkpoint.c | 10 |
1 files changed, 5 insertions, 5 deletions
diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index 7d89e61ef8..08242ac60f 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -249,14 +249,14 @@ next_dev: if (NM_FLAGS_HAS (priv->flags, NM_CHECKPOINT_CREATE_FLAG_DELETE_NEW_CONNECTIONS)) { NMSettingsConnection *con; - gs_free_slist GSList *list = NULL; - GSList *item; + gs_free NMSettingsConnection **list = NULL; + guint i; g_return_val_if_fail (priv->connection_uuids, NULL); - list = nm_settings_get_connections_sorted (nm_settings_get ()); + list = nm_settings_get_connections_sorted (nm_settings_get (), NULL); - for (item = list; item; item = g_slist_next (item)) { - con = item->data; + for (i = 0; list[i]; i++) { + con = list[i]; if (!g_hash_table_contains (priv->connection_uuids, nm_settings_connection_get_uuid (con))) { _LOGD ("rollback: deleting new connection %s (%s)", |
