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
+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
* 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,
* e.g. "File/Save As", "Image/View/Zoom" or "Edit/Select All".
* So a full valid accelerator path may look like:
* "<Gimp-Toolbox>/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,
* 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,
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);
{
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);
* 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
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,
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;
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)
* 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,
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);
}
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);
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;
}
}
-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)
{
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);
*
* 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,
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);
* 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,