[Xfce4-commits] <xfce4-panel:devel> Add a shared hash table for the panel properties.

Nick Schermer nick at xfce.org
Tue Aug 11 20:34:25 CEST 2009


Updating branch refs/heads/devel
         to b64f698aa6982621f4f8c7e2c9264d4b46d78e35 (commit)
       from dfa80d2ce52861da0532cffa9dedd84a26480b47 (commit)

commit b64f698aa6982621f4f8c7e2c9264d4b46d78e35
Author: Nick Schermer <nick at xfce.org>
Date:   Mon Jun 1 01:16:45 2009 +0200

    Add a shared hash table for the panel properties.
    
    The shared table is set during panel startup, the panel will load
    all the properties and all (internal) plugin will use this table
    during startup, which gives a nice performance boost.

 common/panel-xfconf.c     |   25 ++++++++++++++++++++++++-
 common/panel-xfconf.h     |   14 ++++++++------
 panel/panel-application.c |   18 +++++++-----------
 3 files changed, 39 insertions(+), 18 deletions(-)

diff --git a/common/panel-xfconf.c b/common/panel-xfconf.c
index bcf86a3..b2d8957 100644
--- a/common/panel-xfconf.c
+++ b/common/panel-xfconf.c
@@ -50,6 +50,11 @@ static void panel_properties_channel_destroyed (gpointer       user_data,
 
 
 
+/* shared table which is used to speed up the panel startup */
+static GHashTable *shared_hash_table = NULL;
+
+
+
 static void
 panel_properties_object_notify (GObject    *object,
                                 GParamSpec *pspec,
@@ -166,6 +171,8 @@ panel_properties_bind (XfconfChannel       *channel,
   /* get or ref the hash table */
   if (G_LIKELY (hash_table != NULL))
     g_hash_table_ref (hash_table);
+  else if (shared_hash_table != NULL)
+    hash_table = g_hash_table_ref (shared_hash_table);
   else
     hash_table = xfconf_channel_get_properties (channel, property_base);
 
@@ -209,6 +216,22 @@ panel_properties_bind (XfconfChannel       *channel,
     }
 
   /* cleanup */
-  if (hash_table != NULL)
+  if (G_LIKELY (hash_table != NULL))
     g_hash_table_unref (hash_table);
 }
+
+
+
+void
+panel_properties_shared_hash_table (GHashTable *hash_table)
+{
+  /* release previous table */
+  if (shared_hash_table != NULL)
+    g_hash_table_unref (shared_hash_table);
+
+  /* set new table */
+  if (hash_table != NULL)
+    shared_hash_table = g_hash_table_ref (hash_table);
+  else
+    shared_hash_table = NULL;
+}
diff --git a/common/panel-xfconf.h b/common/panel-xfconf.h
index ed28c77..b192e86 100644
--- a/common/panel-xfconf.h
+++ b/common/panel-xfconf.h
@@ -29,12 +29,14 @@ struct _PanelProperty
   GType        type;
 };
 
-void panel_properties_bind   (XfconfChannel       *channel,
-                              GObject             *object,
-                              const gchar         *property_base,
-                              const PanelProperty *properties,
-                              GHashTable          *hash_table);
+void panel_properties_bind              (XfconfChannel       *channel,
+                                         GObject             *object,
+                                         const gchar         *property_base,
+                                         const PanelProperty *properties,
+                                         GHashTable          *hash_table);
 
-void panel_properties_unbind (GObject             *object);
+void panel_properties_unbind            (GObject             *object);
+
+void panel_properties_shared_hash_table (GHashTable          *hash_table);
 
 #endif /* !__PANEL_XFCONF_H__ */
diff --git a/panel/panel-application.c b/panel/panel-application.c
index 396106f..979d90a 100644
--- a/panel/panel-application.c
+++ b/panel/panel-application.c
@@ -114,9 +114,6 @@ struct _PanelApplication
   /* xfconf channel */
   XfconfChannel      *xfconf;
 
-  /* hash table with xfconf properties */
-  GHashTable         *xfconf_properties;
-
   /* internal list of all the panel windows */
   GSList  *windows;
 
@@ -184,7 +181,6 @@ panel_application_init (PanelApplication *application)
   application->drop_uris = NULL;
   application->drop_data_ready = FALSE;
   application->drop_occurred = FALSE;
-  application->xfconf_properties = NULL;
 
   /* get the xfconf channel */
   application->xfconf = xfconf_channel_new ("xfce4-panel");
@@ -275,8 +271,7 @@ panel_application_xfconf_window_bindings (PanelApplication *application,
 
   /* bind all the properties */
   panel_properties_bind (application->xfconf, G_OBJECT (window),
-                         property_base, properties,
-                         application->xfconf_properties);
+                         property_base, properties, NULL);
 
   /* cleanup */
   g_free (property_base);
@@ -301,13 +296,12 @@ panel_application_load (PanelApplication *application)
   panel_return_if_fail (XFCONF_IS_CHANNEL (application->xfconf));
 
   /* get all the panel properties */
-  hash_table = xfconf_channel_get_properties (application->xfconf, "/panels");
+  hash_table = xfconf_channel_get_properties (application->xfconf, NULL);
   if (G_UNLIKELY (hash_table == NULL))
     return;
 
-  /* set the global hash table, so we can quickly read
-   * settings during startup */
-  application->xfconf_properties = hash_table;
+  /* set the shared hash table */
+  panel_properties_shared_hash_table (hash_table);
 
   /* walk all the panel in the configuration */
   value = g_hash_table_lookup (hash_table, "/panels");
@@ -353,9 +347,11 @@ panel_application_load (PanelApplication *application)
         }
     }
 
+  /* unset the shared hash table */
+  panel_properties_shared_hash_table (NULL);
+
   /* cleanup */
   g_hash_table_destroy (hash_table);
-  application->xfconf_properties = NULL;
 }
 
 



More information about the Xfce4-commits mailing list