From b58481b31ec5785d208a7b11df5b05fc50c158e2 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Wed, 15 Nov 2017 16:03:33 +0100 Subject: [PATCH] all: don't use g_direct_equal() for hash table equality function GHashTable optimizes a NULL equality function to use direct pointer comparison. That saves the overhead of calling g_direct_equal(). This is also documented behavior for g_hash_table_new(). While at it, also don't pass g_direct_hash() but use the default of %NULL. The behavior is the same, but consistently don't use g_direct_hash(). --- libnm-glib/nm-client.c | 2 +- libnm/nm-manager.c | 2 +- src/devices/nm-arping-manager.c | 2 +- src/devices/nm-device-factory.c | 2 +- src/devices/nm-device.c | 6 +++--- src/dhcp/nm-dhcp-manager.c | 2 +- src/nm-bus-manager.c | 2 +- src/nm-checkpoint.c | 2 +- src/nm-dispatcher.c | 4 ++-- src/nm-exported-object.c | 4 ++-- src/nm-manager.c | 4 ++-- src/nm-session-monitor.c | 2 +- src/platform/nm-platform.c | 2 +- src/settings/nm-inotify-helper.c | 2 +- 14 files changed, 19 insertions(+), 19 deletions(-) diff --git a/libnm-glib/nm-client.c b/libnm-glib/nm-client.c index f14c8e49bc..183cdc933f 100644 --- a/libnm-glib/nm-client.c +++ b/libnm-glib/nm-client.c @@ -157,7 +157,7 @@ nm_client_init (NMClient *client) priv->state = NM_STATE_UNKNOWN; - priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->permissions = g_hash_table_new (NULL, NULL); } static void diff --git a/libnm/nm-manager.c b/libnm/nm-manager.c index aa749232be..dd689895c1 100644 --- a/libnm/nm-manager.c +++ b/libnm/nm-manager.c @@ -192,7 +192,7 @@ nm_manager_init (NMManager *manager) priv->state = NM_STATE_UNKNOWN; priv->connectivity = NM_CONNECTIVITY_UNKNOWN; - priv->permissions = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->permissions = g_hash_table_new (NULL, NULL); priv->devices = g_ptr_array_new (); priv->all_devices = g_ptr_array_new (); priv->active_connections = g_ptr_array_new (); diff --git a/src/devices/nm-arping-manager.c b/src/devices/nm-arping-manager.c index 51f80e08e4..30e1cf1028 100644 --- a/src/devices/nm-arping-manager.c +++ b/src/devices/nm-arping-manager.c @@ -428,7 +428,7 @@ nm_arping_manager_init (NMArpingManager *self) { NMArpingManagerPrivate *priv = NM_ARPING_MANAGER_GET_PRIVATE (self); - priv->addresses = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->addresses = g_hash_table_new_full (NULL, NULL, NULL, destroy_address_info); priv->state = STATE_INIT; } diff --git a/src/devices/nm-device-factory.c b/src/devices/nm-device-factory.c index 97f011c5e9..86af75e643 100644 --- a/src/devices/nm-device-factory.c +++ b/src/devices/nm-device-factory.c @@ -351,7 +351,7 @@ nm_device_factory_manager_load_factories (NMDeviceFactoryManagerFactoryFunc call g_return_if_fail (factories_by_link == NULL); g_return_if_fail (factories_by_setting == NULL); - factories_by_link = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_object_unref); + factories_by_link = g_hash_table_new_full (NULL, NULL, NULL, g_object_unref); factories_by_setting = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, (GDestroyNotify) factories_list_unref); #define _ADD_INTERNAL(get_type_fcn) \ diff --git a/src/devices/nm-device.c b/src/devices/nm-device.c index 81d8884283..5da88db3d9 100644 --- a/src/devices/nm-device.c +++ b/src/devices/nm-device.c @@ -6217,7 +6217,7 @@ shared4_new_config (NMDevice *self, NMConnection *connection) guint32 count = 0; if (G_UNLIKELY (!shared_ips)) - shared_ips = g_hash_table_new (g_direct_hash, g_direct_equal); + shared_ips = g_hash_table_new (NULL, NULL); else { while (g_hash_table_lookup (shared_ips, GUINT_TO_POINTER (start + count))) { count += ntohl (0x100); @@ -12072,7 +12072,7 @@ nm_device_recheck_available_connections (NMDevice *self) priv = NM_DEVICE_GET_PRIVATE(self); if (g_hash_table_size (priv->available_connections) > 0) { - prune_list = g_hash_table_new (g_direct_hash, g_direct_equal); + prune_list = g_hash_table_new (NULL, NULL); g_hash_table_iter_init (&h_iter, priv->available_connections); while (g_hash_table_iter_next (&h_iter, (gpointer *) &connection, NULL)) g_hash_table_add (prune_list, connection); @@ -14131,7 +14131,7 @@ nm_device_init (NMDevice *self) priv->rfkill_type = RFKILL_TYPE_UNKNOWN; priv->unmanaged_flags = NM_UNMANAGED_PLATFORM_INIT; priv->unmanaged_mask = priv->unmanaged_flags; - priv->available_connections = g_hash_table_new_full (g_direct_hash, g_direct_equal, g_object_unref, NULL); + priv->available_connections = g_hash_table_new_full (NULL, NULL, g_object_unref, NULL); priv->ip6_saved_properties = g_hash_table_new_full (nm_str_hash, g_str_equal, NULL, g_free); priv->sys_iface_state = NM_DEVICE_SYS_IFACE_STATE_EXTERNAL; diff --git a/src/dhcp/nm-dhcp-manager.c b/src/dhcp/nm-dhcp-manager.c index f5c7c84b76..c6f0a24d5d 100644 --- a/src/dhcp/nm-dhcp-manager.c +++ b/src/dhcp/nm-dhcp-manager.c @@ -429,7 +429,7 @@ nm_dhcp_manager_init (NMDhcpManager *self) nm_log_info (LOGD_DHCP, "dhcp-init: Using DHCP client '%s'", client_factory->name); priv->client_factory = client_factory; - priv->clients = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->clients = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_object_unref); } diff --git a/src/nm-bus-manager.c b/src/nm-bus-manager.c index f6b86e903f..d506f9f300 100644 --- a/src/nm-bus-manager.c +++ b/src/nm-bus-manager.c @@ -307,7 +307,7 @@ private_server_new (const char *path, g_signal_connect (server, "new-connection", G_CALLBACK (private_server_new_connection), s); - s->obj_managers = g_hash_table_new_full (g_direct_hash, g_direct_equal, + s->obj_managers = g_hash_table_new_full (NULL, NULL, (GDestroyNotify) private_server_manager_destroy, g_free); s->manager = manager; diff --git a/src/nm-checkpoint.c b/src/nm-checkpoint.c index c3a2e74360..2a2a174909 100644 --- a/src/nm-checkpoint.c +++ b/src/nm-checkpoint.c @@ -466,7 +466,7 @@ nm_checkpoint_init (NMCheckpoint *self) { NMCheckpointPrivate *priv = NM_CHECKPOINT_GET_PRIVATE (self); - priv->devices = g_hash_table_new_full (g_direct_hash, g_direct_equal, + priv->devices = g_hash_table_new_full (NULL, NULL, NULL, device_checkpoint_destroy); } diff --git a/src/nm-dispatcher.c b/src/nm-dispatcher.c index 237afdefe7..b90176416e 100644 --- a/src/nm-dispatcher.c +++ b/src/nm-dispatcher.c @@ -345,8 +345,8 @@ static void _ensure_requests (void) { if (G_UNLIKELY (requests == NULL)) { - requests = g_hash_table_new_full (g_direct_hash, - g_direct_equal, + requests = g_hash_table_new_full (NULL, + NULL, NULL, (GDestroyNotify) dispatcher_info_free); } diff --git a/src/nm-exported-object.c b/src/nm-exported-object.c index 94264caa6e..cf28946398 100644 --- a/src/nm-exported-object.c +++ b/src/nm-exported-object.c @@ -501,8 +501,8 @@ nm_exported_object_create_skeletons (NMExportedObject *self, ifdata->property_changed_signal_id = g_signal_lookup ("properties-changed", G_OBJECT_TYPE (ifdata->interface)); - ifdata->pending_notifies = g_hash_table_new_full (g_direct_hash, - g_direct_equal, + ifdata->pending_notifies = g_hash_table_new_full (NULL, + NULL, NULL, (GDestroyNotify) g_variant_unref); } diff --git a/src/nm-manager.c b/src/nm-manager.c index 06423603b7..e2e7499f86 100644 --- a/src/nm-manager.c +++ b/src/nm-manager.c @@ -3016,7 +3016,7 @@ find_slaves (NMManager *manager, s_con = nm_connection_get_setting_connection (NM_CONNECTION (connection)); g_return_val_if_fail (s_con, NULL); - devices = g_hash_table_new (g_direct_hash, g_direct_equal); + devices = g_hash_table_new (NULL, NULL); /* Search through all connections, not only inactive ones, because * even if a slave was already active, it might be deactivated during @@ -6233,7 +6233,7 @@ nm_manager_init (NMManager *self) priv->timestamp_update_id = g_timeout_add_seconds (300, (GSourceFunc) periodic_update_active_connection_timestamps, self); priv->metered = NM_METERED_UNKNOWN; - priv->sleep_devices = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->sleep_devices = g_hash_table_new (NULL, NULL); } static gboolean diff --git a/src/nm-session-monitor.c b/src/nm-session-monitor.c index 20781bd45d..045c29af4c 100644 --- a/src/nm-session-monitor.c +++ b/src/nm-session-monitor.c @@ -258,7 +258,7 @@ ck_init (NMSessionMonitor *monitor) if (g_file_query_exists (file, NULL)) { if ((monitor->ck.monitor = g_file_monitor_file (file, G_FILE_MONITOR_NONE, NULL, &error))) { - monitor->ck.cache = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, g_free); + monitor->ck.cache = g_hash_table_new_full (NULL, NULL, NULL, g_free); g_signal_connect (monitor->ck.monitor, "changed", G_CALLBACK (ck_changed), diff --git a/src/platform/nm-platform.c b/src/platform/nm-platform.c index f94d93e257..d6332648e4 100644 --- a/src/platform/nm-platform.c +++ b/src/platform/nm-platform.c @@ -594,7 +594,7 @@ nm_platform_link_get_all (NMPlatform *self, gboolean sort_by_name) * further by moving children/slaves to the end. */ g_ptr_array_sort_with_data (links, _link_get_all_presort, GINT_TO_POINTER (sort_by_name)); - unseen = g_hash_table_new (g_direct_hash, g_direct_equal); + unseen = g_hash_table_new (NULL, NULL); for (i = 0; i < links->len; i++) { item = NMP_OBJECT_CAST_LINK (links->pdata[i]); nm_assert (item->ifindex > 0); diff --git a/src/settings/nm-inotify-helper.c b/src/settings/nm-inotify-helper.c index 4c65b02da5..5d190b11a9 100644 --- a/src/settings/nm-inotify-helper.c +++ b/src/settings/nm-inotify-helper.c @@ -172,7 +172,7 @@ nm_inotify_helper_init (NMInotifyHelper *self) { NMInotifyHelperPrivate *priv = NM_INOTIFY_HELPER_GET_PRIVATE (self); - priv->wd_refs = g_hash_table_new (g_direct_hash, g_direct_equal); + priv->wd_refs = g_hash_table_new (NULL, NULL); } static void