gtk+ r20331 - in trunk: . gtk
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gtk+ r20331 - in trunk: . gtk
- Date: Sat, 7 Jun 2008 20:40:20 +0000 (UTC)
Author: chpe
Date: Sat Jun 7 20:40:20 2008
New Revision: 20331
URL: http://svn.gnome.org/viewvc/gtk+?rev=20331&view=rev
Log:
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.
Modified:
trunk/ChangeLog
trunk/gtk/gtkaccelgroup.c
trunk/gtk/gtkaccelmap.c
trunk/gtk/gtkaction.c
trunk/gtk/gtkmenu.c
trunk/gtk/gtkmenuitem.c
trunk/gtk/gtkwidget.c
Modified: trunk/gtk/gtkaccelgroup.c
==============================================================================
--- trunk/gtk/gtkaccelgroup.c (original)
+++ trunk/gtk/gtkaccelgroup.c Sat Jun 7 20:40:20 2008
@@ -525,6 +525,10 @@
* 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,
Modified: trunk/gtk/gtkaccelmap.c
==============================================================================
--- trunk/gtk/gtkaccelmap.c (original)
+++ trunk/gtk/gtkaccelmap.c Sat Jun 7 20:40:20 2008
@@ -149,6 +149,10 @@
* 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,
@@ -429,6 +433,10 @@
* 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,
Modified: trunk/gtk/gtkaction.c
==============================================================================
--- trunk/gtk/gtkaction.c (original)
+++ trunk/gtk/gtkaction.c Sat Jun 7 20:40:20 2008
@@ -119,9 +119,7 @@
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 @@
{
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 @@
* 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
Modified: trunk/gtk/gtkmenu.c
==============================================================================
--- trunk/gtk/gtkmenu.c (original)
+++ trunk/gtk/gtkmenu.c Sat Jun 7 20:40:20 2008
@@ -152,7 +152,6 @@
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 @@
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;
@@ -964,16 +962,6 @@
}
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 @@
* 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 @@
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);
}
Modified: trunk/gtk/gtkmenuitem.c
==============================================================================
--- trunk/gtk/gtkmenuitem.c (original)
+++ trunk/gtk/gtkmenuitem.c Sat Jun 7 20:40:20 2008
@@ -64,7 +64,6 @@
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 @@
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 @@
}
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 @@
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 @@
*
* 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 @@
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);
Modified: trunk/gtk/gtkwidget.c
==============================================================================
--- trunk/gtk/gtkwidget.c (original)
+++ trunk/gtk/gtkwidget.c Sat Jun 7 20:40:20 2008
@@ -4344,6 +4344,10 @@
* 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,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]