forked from AuroraMiddleware/gtk
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
This commit is contained in:
parent
2048ec5925
commit
bd48f263ce
11
ChangeLog
11
ChangeLog
@ -1,3 +1,14 @@
|
||||
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.
|
||||
|
||||
2007-07-10 Richard Hult <richard@imendio.com>
|
||||
|
||||
* gdk/quartz/gdkwindow-quartz.c: (gdk_window_new),
|
||||
|
@ -54,7 +54,7 @@
|
||||
|
||||
struct _GtkActionPrivate
|
||||
{
|
||||
gchar *name;
|
||||
const gchar *name; /* interned */
|
||||
gchar *label;
|
||||
gchar *short_label;
|
||||
gchar *tooltip;
|
||||
@ -398,12 +398,9 @@ static void
|
||||
gtk_action_buildable_set_name (GtkBuildable *buildable,
|
||||
const gchar *name)
|
||||
{
|
||||
gchar *tmp;
|
||||
GtkAction *action = GTK_ACTION (buildable);
|
||||
|
||||
tmp = action->private_data->name;
|
||||
action->private_data->name = g_strdup (name);
|
||||
g_free (tmp);
|
||||
action->private_data->name = g_intern_string (name);
|
||||
}
|
||||
|
||||
static const gchar *
|
||||
@ -455,7 +452,6 @@ gtk_action_finalize (GObject *object)
|
||||
GtkAction *action;
|
||||
action = GTK_ACTION (object);
|
||||
|
||||
g_free (action->private_data->name);
|
||||
g_free (action->private_data->label);
|
||||
g_free (action->private_data->short_label);
|
||||
g_free (action->private_data->tooltip);
|
||||
@ -476,16 +472,13 @@ gtk_action_set_property (GObject *object,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkAction *action;
|
||||
gchar *tmp;
|
||||
|
||||
action = GTK_ACTION (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
tmp = action->private_data->name;
|
||||
action->private_data->name = g_value_dup_string (value);
|
||||
g_free (tmp);
|
||||
action->private_data->name = g_intern_string (g_value_get_string (value));
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
gtk_action_set_label (action, g_value_get_string (value));
|
||||
@ -545,7 +538,7 @@ gtk_action_get_property (GObject *object,
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_NAME:
|
||||
g_value_set_string (value, action->private_data->name);
|
||||
g_value_set_static_string (value, action->private_data->name);
|
||||
break;
|
||||
case PROP_LABEL:
|
||||
g_value_set_string (value, action->private_data->label);
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user