[gnome-software] gs-plugin-loader: Rework some hash table code to use fewer calls
- From: Richard Hughes <rhughes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-software] gs-plugin-loader: Rework some hash table code to use fewer calls
- Date: Wed, 8 Apr 2020 20:02:33 +0000 (UTC)
commit 1e096d1fa82173bf19fa929d670873ab3037f117
Author: Philip Withnall <withnall endlessm com>
Date: Thu Apr 2 10:41:39 2020 +0100
gs-plugin-loader: Rework some hash table code to use fewer calls
This won’t affect performance much, but does make the code a little
cleaner. There’s no need to query whether an element exists in a hash
table before removing it or updating it: instead, check the return
value from the remove/update function.
Signed-off-by: Philip Withnall <withnall endlessm com>
lib/gs-plugin-loader.c | 32 ++++++++++++++++----------------
1 file changed, 16 insertions(+), 16 deletions(-)
---
diff --git a/lib/gs-plugin-loader.c b/lib/gs-plugin-loader.c
index 59c3d3e6..c8136f1c 100644
--- a/lib/gs-plugin-loader.c
+++ b/lib/gs-plugin-loader.c
@@ -1962,30 +1962,30 @@ gs_plugin_loader_allow_updates_cb (GsPlugin *plugin,
GsPluginLoader *plugin_loader)
{
GsPluginLoaderPrivate *priv = gs_plugin_loader_get_instance_private (plugin_loader);
- gpointer exists;
+ gboolean changed = FALSE;
/* plugin now allowing gnome-software to show updates panel */
- exists = g_hash_table_lookup (priv->disallow_updates, plugin);
if (allow_updates) {
- if (exists == NULL)
- return;
- g_debug ("plugin %s no longer inhibited managed updates",
- gs_plugin_get_name (plugin));
- g_hash_table_remove (priv->disallow_updates, plugin);
+ if (g_hash_table_remove (priv->disallow_updates, plugin)) {
+ g_debug ("plugin %s no longer inhibited managed updates",
+ gs_plugin_get_name (plugin));
+ changed = TRUE;
+ }
/* plugin preventing the updates panel from being shown */
} else {
- if (exists != NULL)
- return;
- g_debug ("plugin %s inhibited managed updates",
- gs_plugin_get_name (plugin));
- g_hash_table_insert (priv->disallow_updates,
- (gpointer) plugin,
- (gpointer) gs_plugin_get_name (plugin));
+ if (g_hash_table_replace (priv->disallow_updates,
+ (gpointer) plugin,
+ (gpointer) gs_plugin_get_name (plugin))) {
+ g_debug ("plugin %s inhibited managed updates",
+ gs_plugin_get_name (plugin));
+ changed = TRUE;
+ }
}
- /* something possibly changed, so notify display layer */
- g_object_notify (G_OBJECT (plugin_loader), "allow-updates");
+ /* notify display layer */
+ if (changed)
+ g_object_notify (G_OBJECT (plugin_loader), "allow-updates");
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]