summaryrefslogtreecommitdiff
path: root/gtk/gtkactiongroup.c
diff options
context:
space:
mode:
authorChristian Persch <chpe@gnome.org>2007-07-10 22:18:08 +0000
committerChristian Persch <chpe@src.gnome.org>2007-07-10 22:18:08 +0000
commitbd48f263ceb208d8bc2a7582a713aa4014791d61 (patch)
tree55688893c07a4b04055602b59798006bc0da6130 /gtk/gtkactiongroup.c
parent2048ec5925a4f94b8485ac0db1582e200e3799a9 (diff)
downloadgtk+-bd48f263ceb208d8bc2a7582a713aa4014791d61.tar.gz
Intern the action's name. Saves two string duplicates of it per action;
2007-07-11 Christian Persch <chpe@gnome.org> * gtk/gtkaction.c: (gtk_action_buildable_set_name), (gtk_action_finalize), (gtk_action_set_property), (gtk_action_get_property): * gtk/gtkactiongroup.c: (gtk_action_group_init), (gtk_action_group_add_action), (gtk_action_group_add_action_with_accel), (gtk_action_group_remove_action): Intern the action's name. Saves two string duplicates of it per action; bug #455645. svn path=/trunk/; revision=18441
Diffstat (limited to 'gtk/gtkactiongroup.c')
-rw-r--r--gtk/gtkactiongroup.c50
1 files changed, 30 insertions, 20 deletions
diff --git a/gtk/gtkactiongroup.c b/gtk/gtkactiongroup.c
index b9d6ee0837..3a86464950 100644
--- a/gtk/gtkactiongroup.c
+++ b/gtk/gtkactiongroup.c
@@ -298,7 +298,7 @@ gtk_action_group_init (GtkActionGroup *self)
self->private_data->sensitive = TRUE;
self->private_data->visible = TRUE;
self->private_data->actions = g_hash_table_new_full (g_str_hash, g_str_equal,
- (GDestroyNotify) g_free,
+ NULL,
(GDestroyNotify) remove_action);
self->private_data->translate_func = NULL;
self->private_data->translate_data = NULL;
@@ -743,15 +743,19 @@ void
gtk_action_group_add_action (GtkActionGroup *action_group,
GtkAction *action)
{
+ const gchar *name;
+
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
g_return_if_fail (GTK_IS_ACTION (action));
- g_return_if_fail (gtk_action_get_name (action) != NULL);
+
+ name = gtk_action_get_name (action);
+ g_return_if_fail (name != NULL);
- if (!check_unique_action (action_group, gtk_action_get_name (action)))
+ if (!check_unique_action (action_group, name))
return;
g_hash_table_insert (action_group->private_data->actions,
- g_strdup (gtk_action_get_name (action)),
+ (gpointer) name,
g_object_ref (action));
g_object_set (action, I_("action-group"), action_group, NULL);
}
@@ -782,14 +786,11 @@ gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
gchar *accel_path;
guint accel_key = 0;
GdkModifierType accel_mods;
- GtkStockItem stock_item;
- gchar *name;
- gchar *stock_id;
+ const gchar *name;
- if (!check_unique_action (action_group, gtk_action_get_name (action)))
+ name = gtk_action_get_name (action);
+ if (!check_unique_action (action_group, name))
return;
-
- g_object_get (action, "name", &name, "stock-id", &stock_id, NULL);
accel_path = g_strconcat ("<Actions>/",
action_group->private_data->name, "/", name, NULL);
@@ -806,10 +807,20 @@ gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
accelerator, name);
}
}
- else if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
+ else
{
- accel_key = stock_item.keyval;
- accel_mods = stock_item.modifier;
+ gchar *stock_id;
+ GtkStockItem stock_item;
+
+ g_object_get (action, "stock-id", &stock_id, NULL);
+
+ if (stock_id && gtk_stock_lookup (stock_id, &stock_item))
+ {
+ accel_key = stock_item.keyval;
+ accel_mods = stock_item.modifier;
+ }
+
+ g_free (stock_id);
}
if (accel_key)
@@ -819,8 +830,6 @@ gtk_action_group_add_action_with_accel (GtkActionGroup *action_group,
gtk_action_group_add_action (action_group, action);
g_free (accel_path);
- g_free (stock_id);
- g_free (name);
}
/**
@@ -836,14 +845,15 @@ void
gtk_action_group_remove_action (GtkActionGroup *action_group,
GtkAction *action)
{
+ const gchar *name;
+
g_return_if_fail (GTK_IS_ACTION_GROUP (action_group));
g_return_if_fail (GTK_IS_ACTION (action));
- g_return_if_fail (gtk_action_get_name (action) != NULL);
- /* extra protection to make sure action->name is valid */
- g_object_ref (action);
- g_hash_table_remove (action_group->private_data->actions, gtk_action_get_name (action));
- g_object_unref (action);
+ name = gtk_action_get_name (action);
+ g_return_if_fail (name != NULL);
+
+ g_hash_table_remove (action_group->private_data->actions, name);
}
static void