]> Pileus Git - ~andy/gtk/commitdiff
Bug 535608 – do not string-copy accel paths in the menu code
authorChristian Persch <chpe@src.gnome.org>
Sat, 7 Jun 2008 20:40:20 +0000 (20:40 +0000)
committerChristian Persch <chpe@src.gnome.org>
Sat, 7 Jun 2008 20:40:20 +0000 (20:40 +0000)
Don't store the accel path as a string in gtkmenu/gtkmenuitem.
The accel path will be interned anyway, so keeping a string copy around
is just a waste of memory.
Improve the documentation to mention this.

svn path=/trunk/; revision=20331

ChangeLog
gtk/gtkaccelgroup.c
gtk/gtkaccelmap.c
gtk/gtkaction.c
gtk/gtkmenu.c
gtk/gtkmenuitem.c
gtk/gtkwidget.c

index fd381d3e4be1e6bb8ad5d4f47607430c064779ce..0689322e26f69e0663e2512075b08ce70116e4c3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2008-06-08  Christian Persch <chpe@gnome.org>
+
+       Bug 535608 – do not string-copy accel paths in the menu code
+
+        * gtk/gtkaccelgroup.c:
+        * gtk/gtkaccelmap.c:
+        * gtk/gtkaction.c:
+        * gtk/gtkmenu.c:
+        * gtk/gtkmenuitem.c:
+        * gtk/gtkwidget.c:  Don't store the accel path as a string in
+        gtkmenu/gtkmenuitem. The accel path will be interned anyway, so
+        keeping a string copy around is just a waste of memory.
+        Improve the documentation to mention this.
+
 2008-06-07  Tor Lillqvist  <tml@novell.com>
 
        Bug 536990 - updateiconcache.c: 'close ()' is redundant
index cc7df18d02fd2dc2748d7f4fbf5def0ca1987303..30b2aa605115ec4a8c2afc5265e6a390c1b6c9a9 100644 (file)
@@ -525,6 +525,10 @@ gtk_accel_group_connect (GtkAccelGroup     *accel_group,
  * for the path.
  *
  * The signature used for the @closure is that of #GtkAccelGroupActivate.
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 void
 gtk_accel_group_connect_by_path (GtkAccelGroup *accel_group,
index 4756035ae27fb3eca6a8e9ca99b6c29ed980d436..c193baaaf8b92659e274ab527e54ee88643eaea7 100644 (file)
@@ -149,6 +149,10 @@ _gtk_accel_path_is_valid (const gchar *accel_path)
  * e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
  * So a full valid accelerator path may look like:
  * "&lt;Gimp-Toolbox&gt;/File/Dialogs/Tool Options...".
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 void
 gtk_accel_map_add_entry (const gchar    *accel_path,
@@ -429,6 +433,10 @@ internal_change_entry (const gchar    *accel_path,
  * conflicts. A change will only occur if all conflicts could be resolved (which
  * might not be the case if conflicting accelerators are locked). Successful
  * changes are indicated by a %TRUE return value.
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 gboolean
 gtk_accel_map_change_entry (const gchar    *accel_path,
index 22fb10812c6444ba7e2bea458ddd7f97d2a1c79e..f7d3a7ad3481b7320f414fe1a898bc66d39cc783 100644 (file)
@@ -119,9 +119,7 @@ G_DEFINE_TYPE_WITH_CODE (GtkAction, gtk_action, G_TYPE_OBJECT,
                                                gtk_action_buildable_init))
 
 
-static GQuark      accel_path_id  = 0;
 static GQuark      quark_gtk_action_proxy  = 0;
-static const gchar accel_path_key[] = "GtkAction::accel_path";
 static const gchar gtk_action_proxy_key[] = "gtk-action";
 
 static void gtk_action_finalize     (GObject *object);
@@ -176,7 +174,6 @@ gtk_action_class_init (GtkActionClass *klass)
 {
   GObjectClass *gobject_class;
 
-  accel_path_id = g_quark_from_static_string (accel_path_key);
   quark_gtk_action_proxy = g_quark_from_static_string (gtk_action_proxy_key);
 
   gobject_class = G_OBJECT_CLASS (klass);
@@ -1662,6 +1659,10 @@ gtk_action_set_action_group (GtkAction       *action,
  * with the action will have this accel path, so that their
  * accelerators are consistent.
  *
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
+ *
  * Since: 2.4
  */
 void
index 027e312d9347c08e5bdb87ffe2bcf352756009ca..75fad41251457542778cb5b225862fca972a579c 100644 (file)
@@ -152,7 +152,6 @@ static void     gtk_menu_get_child_property(GtkContainer     *container,
                                             GValue           *value,
                                             GParamSpec       *pspec);
 static void     gtk_menu_destroy           (GtkObject        *object);
-static void     gtk_menu_finalize          (GObject          *object);
 static void     gtk_menu_realize           (GtkWidget        *widget);
 static void     gtk_menu_unrealize         (GtkWidget        *widget);
 static void     gtk_menu_size_request      (GtkWidget        *widget,
@@ -438,7 +437,6 @@ gtk_menu_class_init (GtkMenuClass *class)
   GtkMenuShellClass *menu_shell_class = GTK_MENU_SHELL_CLASS (class);
   GtkBindingSet *binding_set;
   
-  gobject_class->finalize = gtk_menu_finalize;
   gobject_class->set_property = gtk_menu_set_property;
   gobject_class->get_property = gtk_menu_get_property;
 
@@ -963,16 +961,6 @@ gtk_menu_destroy (GtkObject *object)
   GTK_OBJECT_CLASS (gtk_menu_parent_class)->destroy (object);
 }
 
-static void
-gtk_menu_finalize (GObject *object)
-{
-  GtkMenu *menu = GTK_MENU (object);
-
-  g_free (menu->accel_path);
-  
-  G_OBJECT_CLASS (gtk_menu_parent_class)->finalize (object);
-}
-
 static void
 menu_change_screen (GtkMenu   *menu,
                    GdkScreen *new_screen)
@@ -1646,6 +1634,10 @@ gtk_menu_real_can_activate_accel (GtkWidget *widget,
  * Assigning accel paths to menu items then enables the user to change
  * their accelerators at runtime. More details about accelerator paths
  * and their default setups can be found at gtk_accel_map_add_entry().
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 void
 gtk_menu_set_accel_path (GtkMenu     *menu,
@@ -1657,9 +1649,7 @@ gtk_menu_set_accel_path (GtkMenu     *menu,
   if (accel_path)
     g_return_if_fail (accel_path[0] == '<' && strchr (accel_path, '/')); /* simplistic check */
 
-  old_accel_path = menu->accel_path;
-  menu->accel_path = g_strdup (accel_path);
-  g_free (old_accel_path);
+  menu->accel_path = g_intern_string (accel_path);
   if (menu->accel_path)
     _gtk_menu_refresh_accel_paths (menu, FALSE);
 }
index 050ff93253017b134fa6526c2611e10465a1e750..73f1f17a983ec68672f9e13ef5b33b02fb0798dd 100644 (file)
@@ -64,7 +64,6 @@ static void gtk_menu_item_get_property   (GObject          *object,
                                          guint             prop_id,
                                          GValue           *value,
                                          GParamSpec       *pspec);
-static void gtk_menu_item_finalize       (GObject          *object);
 static void gtk_menu_item_destroy        (GtkObject        *object);
 static void gtk_menu_item_size_request   (GtkWidget        *widget,
                                          GtkRequisition   *requisition);
@@ -123,7 +122,6 @@ gtk_menu_item_class_init (GtkMenuItemClass *klass)
 
   gobject_class->set_property = gtk_menu_item_set_property;
   gobject_class->get_property = gtk_menu_item_get_property;
-  gobject_class->finalize = gtk_menu_item_finalize;
 
   object_class->destroy = gtk_menu_item_destroy;
 
@@ -361,16 +359,6 @@ gtk_menu_item_get_property (GObject    *object,
     }
 }
 
-static void
-gtk_menu_item_finalize (GObject *object)
-{
-  GtkMenuItem *menu_item = GTK_MENU_ITEM (object);
-
-  g_free (menu_item->accel_path);
-
-  G_OBJECT_CLASS (gtk_menu_item_parent_class)->finalize (object);
-}
-
 static void
 gtk_menu_item_destroy (GtkObject *object)
 {
@@ -1567,14 +1555,19 @@ _gtk_menu_item_refresh_accel_path (GtkMenuItem   *menu_item,
       path = menu_item->accel_path;
       if (!path && prefix)
        {
-         gchar *postfix = NULL;
+         const gchar *postfix = NULL;
+          gchar *new_path;
 
          /* try to construct one from label text */
          gtk_container_foreach (GTK_CONTAINER (menu_item),
                                 gtk_menu_item_accel_name_foreach,
                                 &postfix);
-         menu_item->accel_path = postfix ? g_strconcat (prefix, "/", postfix, NULL) : NULL;
-         path = menu_item->accel_path;
+          if (postfix)
+            {
+              new_path = g_strconcat (prefix, "/", postfix, NULL);
+              path = menu_item->accel_path = g_intern_string (new_path);
+              g_free (new_path);
+            }
        }
       if (path)
        gtk_widget_set_accel_path (widget, path, accel_group);
@@ -1603,6 +1596,10 @@ _gtk_menu_item_refresh_accel_path (GtkMenuItem   *menu_item,
  *
  * Note that you do need to set an accelerator on the parent menu with
  * gtk_menu_set_accel_group() for this to work.
+ *
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  */
 void
 gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
@@ -1618,9 +1615,7 @@ gtk_menu_item_set_accel_path (GtkMenuItem *menu_item,
   widget = GTK_WIDGET (menu_item);
 
   /* store new path */
-  old_accel_path = menu_item->accel_path;
-  menu_item->accel_path = g_strdup (accel_path);
-  g_free (old_accel_path);
+  menu_item->accel_path = g_intern_string (accel_path);
 
   /* forget accelerators associated with old path */
   gtk_widget_set_accel_path (widget, NULL, NULL);
index 2d10cd854f47ce675febdaa19bea206260118378..aa5402d7c2d7ada82675f6ab97b04294e670091c 100644 (file)
@@ -4344,6 +4344,10 @@ destroy_accel_path (gpointer data)
  * Even when you you aren't using #GtkUIManager, if you only want to
  * set up accelerators on menu items gtk_menu_item_set_accel_path()
  * provides a somewhat more convenient interface.
+ * 
+ * Note that @accel_path string will be stored in a #GQuark. Therefore, if you
+ * pass a static string, you can save some memory by interning it first with 
+ * g_intern_static_string().
  **/
 void
 gtk_widget_set_accel_path (GtkWidget     *widget,