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.
This commit is contained in:
Thomas Haller
2018-04-22 13:01:20 +02:00
parent 1b5925ce88
commit feb1ec1e87

View File

@@ -493,21 +493,28 @@ nm_settings_get_connection_by_path (NMSettings *self, const char *path)
gboolean gboolean
nm_settings_has_connection (NMSettings *self, NMSettingsConnection *connection) nm_settings_has_connection (NMSettings *self, NMSettingsConnection *connection)
{ {
NMSettingsConnection *candidate = NULL; gboolean has;
const char *path;
g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE); g_return_val_if_fail (NM_IS_SETTINGS (self), FALSE);
g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE); g_return_val_if_fail (NM_IS_SETTINGS_CONNECTION (connection), FALSE);
path = nm_dbus_object_get_path (NM_DBUS_OBJECT (connection)); has = !c_list_is_empty (&connection->_connections_lst);
if (path)
candidate = nm_settings_get_connection_by_path (self, path);
nm_assert (!candidate || candidate == connection); nm_assert (has == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head,
nm_assert (!!candidate == nm_c_list_contains_entry (&NM_SETTINGS_GET_PRIVATE (self)->connections_lst_head, connection,
connection, _connections_lst));
_connections_lst)); nm_assert (({
return !!candidate; 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));
}));
return has;
} }
const GSList * const GSList *