summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2018-10-22 14:43:48 +0200
committerThomas Haller <thaller@redhat.com>2018-10-22 15:17:29 +0200
commit0dc4d950995bef59108549743a89b520ff9dfc93 (patch)
tree1ff25fba3aa21608fefc886853cee24e7c550729
parentbbdcb2e7a27b675a59fefec8cc1a6f3ed0284fa8 (diff)
downloadNetworkManager-th/setting-hash.tar.gz
libnm: hash settings in NMConnection by gtypeth/setting-hash
NMConnection keeps a list (hash table) of all settings. There are two lookup methods to find a setting in a connection: - nm_connection_get_setting() by GType - nm_connection_get_setting_by_name() by name Note, that nm_connection_get_setting_by_name() first converts the name to a GType, and then looks up the setting by GType. But theni, it would again convert the GType to the type name, and hash the name. That is pointless, just index by type directly. Maybe, using a hash table is anyway overkill because commonly there are only a handful of settings in a connection. Regardless of that, change the hashing.
-rw-r--r--libnm-core/nm-connection.c28
1 files changed, 14 insertions, 14 deletions
diff --git a/libnm-core/nm-connection.c b/libnm-core/nm-connection.c
index a19a09dcd8..c96000789e 100644
--- a/libnm-core/nm-connection.c
+++ b/libnm-core/nm-connection.c
@@ -94,18 +94,18 @@ static void
_nm_connection_add_setting (NMConnection *connection, NMSetting *setting)
{
NMConnectionPrivate *priv;
- const char *name;
+ GType setting_type;
NMSetting *s_old;
nm_assert (NM_IS_CONNECTION (connection));
nm_assert (NM_IS_SETTING (setting));
priv = NM_CONNECTION_GET_PRIVATE (connection);
- name = G_OBJECT_TYPE_NAME (setting);
+ setting_type = G_OBJECT_TYPE (setting);
- if ((s_old = g_hash_table_lookup (priv->settings, (gpointer) name)))
+ if ((s_old = g_hash_table_lookup (priv->settings, GSIZE_TO_POINTER (setting_type))))
g_signal_handlers_disconnect_by_func (s_old, setting_changed_cb, connection);
- g_hash_table_insert (priv->settings, (gpointer) name, setting);
+ g_hash_table_insert (priv->settings, GSIZE_TO_POINTER (setting_type), setting);
/* Listen for property changes so we can emit the 'changed' signal */
g_signal_connect (setting, "notify", (GCallback) setting_changed_cb, connection);
}
@@ -135,17 +135,15 @@ _nm_connection_remove_setting (NMConnection *connection, GType setting_type)
{
NMConnectionPrivate *priv;
NMSetting *setting;
- const char *setting_name;
g_return_val_if_fail (NM_IS_CONNECTION (connection), FALSE);
g_return_val_if_fail (g_type_is_a (setting_type, NM_TYPE_SETTING), FALSE);
priv = NM_CONNECTION_GET_PRIVATE (connection);
- setting_name = g_type_name (setting_type);
- setting = g_hash_table_lookup (priv->settings, setting_name);
+ setting = g_hash_table_lookup (priv->settings, GSIZE_TO_POINTER (setting_type));
if (setting) {
g_signal_handlers_disconnect_by_func (setting, setting_changed_cb, connection);
- g_hash_table_remove (priv->settings, setting_name);
+ g_hash_table_remove (priv->settings, GSIZE_TO_POINTER (setting_type));
g_signal_emit (connection, signals[CHANGED], 0);
return TRUE;
}
@@ -175,7 +173,7 @@ _connection_get_setting (NMConnection *connection, GType setting_type)
nm_assert (g_type_is_a (setting_type, NM_TYPE_SETTING));
setting = g_hash_table_lookup (NM_CONNECTION_GET_PRIVATE (connection)->settings,
- g_type_name (setting_type));
+ GSIZE_TO_POINTER (setting_type));
nm_assert (!setting || G_TYPE_CHECK_INSTANCE_TYPE (setting, setting_type));
return setting;
}
@@ -1878,7 +1876,7 @@ nm_connection_to_dbus (NMConnection *connection,
NMConnectionPrivate *priv;
GVariantBuilder builder;
GHashTableIter iter;
- gpointer key, data;
+ gpointer data;
GVariant *setting_dict, *ret;
g_return_val_if_fail (NM_IS_CONNECTION (connection), NULL);
@@ -1888,7 +1886,7 @@ nm_connection_to_dbus (NMConnection *connection,
/* Add each setting's hash to the main hash */
g_hash_table_iter_init (&iter, priv->settings);
- while (g_hash_table_iter_next (&iter, &key, &data)) {
+ while (g_hash_table_iter_next (&iter, NULL, &data)) {
NMSetting *setting = NM_SETTING (data);
setting_dict = _nm_setting_to_dbus (setting, connection, flags);
@@ -2033,14 +2031,13 @@ nm_connection_dump (NMConnection *connection)
{
GHashTableIter iter;
NMSetting *setting;
- const char *setting_name;
char *str;
if (!connection)
return;
g_hash_table_iter_init (&iter, NM_CONNECTION_GET_PRIVATE (connection)->settings);
- while (g_hash_table_iter_next (&iter, (gpointer) &setting_name, (gpointer) &setting)) {
+ while (g_hash_table_iter_next (&iter, NULL, (gpointer) &setting)) {
str = nm_setting_to_string (setting);
g_print ("%s\n", str);
g_free (str);
@@ -2914,7 +2911,10 @@ nm_connection_get_private (NMConnection *connection)
priv, (GDestroyNotify) nm_connection_private_free);
priv->self = connection;
- priv->settings = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_object_unref);
+ priv->settings = g_hash_table_new_full (nm_direct_hash,
+ NULL,
+ NULL,
+ g_object_unref);
}
return priv;