diff options
author | Christian Persch <chpe@src.gnome.org> | 2008-06-07 20:40:20 +0000 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2008-06-07 20:40:20 +0000 |
commit | dcc94280362d27cb980bfb8e5a3b1db40874a027 (patch) | |
tree | 5605939127d36993c90f7e3840b039521d5b4981 /gtk/gtkmenuitem.c | |
parent | e2642ac9d2d4652e7583ff8962896c6b9dd3ac5f (diff) | |
download | gtk+-dcc94280362d27cb980bfb8e5a3b1db40874a027.tar.gz |
Bug 535608 – do not string-copy accel paths in the menu code
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
Diffstat (limited to 'gtk/gtkmenuitem.c')
-rw-r--r-- | gtk/gtkmenuitem.c | 31 |
1 files changed, 13 insertions, 18 deletions
diff --git a/gtk/gtkmenuitem.c b/gtk/gtkmenuitem.c index 050ff93253..73f1f17a98 100644 --- a/gtk/gtkmenuitem.c +++ b/gtk/gtkmenuitem.c @@ -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; @@ -362,16 +360,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) { GtkMenuItem *menu_item = GTK_MENU_ITEM (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); |