diff options
author | Thomas Haller <thaller@redhat.com> | 2018-04-22 13:01:20 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2018-04-30 16:36:29 +0200 |
commit | feb1ec1e879146b88c6ee23ddf5ed37b2ec83ec5 (patch) | |
tree | 5ec4a44c2ca43915bc96031d4acfc4a29b0b1a40 | |
parent | 1b5925ce881370a1aba347cea0afe61e6316e81a (diff) | |
download | NetworkManager-feb1ec1e879146b88c6ee23ddf5ed37b2ec83ec5.tar.gz |
settings: avoid lookup in nm_settings_has_connection()
There is no need to perform a lookup by path. NMSettings is a singleton,
it has the connection exactly iff the connection is linked.
Also add an assertion to double-check that the results agree with
the previous implementation.
-rw-r--r-- | src/settings/nm-settings.c | 27 |
1 files changed, 17 insertions, 10 deletions
diff --git a/src/settings/nm-settings.c b/src/settings/nm-settings.c index a9a1c34389..e792fd78d9 100644 --- a/src/settings/nm-settings.c +++ b/src/settings/nm-settings.c @@ -493,21 +493,28 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path) gboolean nm_settings_has_connection (NMSettings *self, NMSettingsConnection *connection) { - NMSettingsConnection *candidate = NULL; - const char *path; + gboolean has; g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); - path = nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)); - if (path) - candidate = nm_settings_get_connection_by_path (self, path); + has = !c_list_is_empty (&connection->_connections_lst); + + nm_assert (has == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head, + connection, + _connections_lst)); + nm_assert (({ + NMSettingsConnection *candidate = NULL; + const char *path; + + path = nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)); + if (path) + candidate = nm_settings_get_connection_by_path (self, path); + + (has == (connection == candidate)); + })); - nm_assert (!candidate || candidate == connection); - nm_assert (!!candidate == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head, - connection, - _connections_lst)); - return !!candidate; + return has; } const GSList * |