use a hash table instead of object data to maintain context ids. Saves

2006-09-01  Sven Neumann  <sven@gimp.org>

	* app/display/gimpstatusbar.c: use a hash table instead of object
	data to maintain context ids. Saves lots of pointless string copies.
This commit is contained in:
Sven Neumann 2006-09-01 12:15:14 +00:00 committed by Sven Neumann
parent 14f3860b96
commit 297f871514
3 changed files with 27 additions and 37 deletions

View File

@ -1,6 +1,7 @@
2006-09-01 Sven Neumann <sven@gimp.org> 2006-09-01 Sven Neumann <sven@gimp.org>
* app/display/gimpstatusbar.c: minor cleanup. * app/display/gimpstatusbar.[ch]: use a hash table instead of object
data to maintain context ids. Saves lots of pointless string copies.
2006-09-01 Michael Natterer <mitch@gimp.org> 2006-09-01 Michael Natterer <mitch@gimp.org>

View File

@ -1,5 +1,5 @@
/* The GIMP -- an image manipulation program /* The GIMP -- an image manipulation program Copyright (C) 1995
* Copyright (C) 1995 Spencer Kimball and Peter Mattis * Spencer Kimball and Peter Mattis
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by * it under the terms of the GNU General Public License as published by
@ -59,7 +59,7 @@ struct _GimpStatusbarMsg
static void gimp_statusbar_progress_iface_init (GimpProgressInterface *iface); static void gimp_statusbar_progress_iface_init (GimpProgressInterface *iface);
static void gimp_statusbar_destroy (GtkObject *object); static void gimp_statusbar_finalize (GObject *object);
static GimpProgress * static GimpProgress *
gimp_statusbar_progress_start (GimpProgress *progress, gimp_statusbar_progress_start (GimpProgress *progress,
@ -97,10 +97,10 @@ G_DEFINE_TYPE_WITH_CODE (GimpStatusbar, gimp_statusbar, GTK_TYPE_HBOX,
static void static void
gimp_statusbar_class_init (GimpStatusbarClass *klass) gimp_statusbar_class_init (GimpStatusbarClass *klass)
{ {
GtkObjectClass *object_class = GTK_OBJECT_CLASS (klass); GObjectClass *object_class = G_OBJECT_CLASS (klass);
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass); GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
object_class->destroy = gimp_statusbar_destroy; object_class->finalize = gimp_statusbar_finalize;
gtk_widget_class_install_style_property (widget_class, gtk_widget_class_install_style_property (widget_class,
g_param_spec_enum ("shadow-type", g_param_spec_enum ("shadow-type",
@ -207,9 +207,10 @@ gimp_statusbar_init (GimpStatusbar *statusbar)
gtk_progress_bar_set_text (GTK_PROGRESS_BAR (statusbar->progressbar), "GIMP"); gtk_progress_bar_set_text (GTK_PROGRESS_BAR (statusbar->progressbar), "GIMP");
statusbar->context_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
statusbar->seq_context_id = 1; statusbar->seq_context_id = 1;
statusbar->messages = NULL; statusbar->messages = NULL;
statusbar->keys = NULL;
} }
static void static void
@ -225,7 +226,7 @@ gimp_statusbar_progress_iface_init (GimpProgressInterface *iface)
} }
static void static void
gimp_statusbar_destroy (GtkObject *object) gimp_statusbar_finalize (GObject *object)
{ {
GimpStatusbar *statusbar = GIMP_STATUSBAR (object); GimpStatusbar *statusbar = GIMP_STATUSBAR (object);
GSList *list; GSList *list;
@ -241,13 +242,10 @@ gimp_statusbar_destroy (GtkObject *object)
g_slist_free (statusbar->messages); g_slist_free (statusbar->messages);
statusbar->messages = NULL; statusbar->messages = NULL;
for (list = statusbar->keys; list; list = list->next) g_hash_table_destroy (statusbar->context_ids);
g_free (list->data); statusbar->context_ids = NULL;
g_slist_free (statusbar->keys); G_OBJECT_CLASS (parent_class)->finalize (object);
statusbar->keys = NULL;
GTK_OBJECT_CLASS (parent_class)->destroy (object);
} }
static GimpProgress * static GimpProgress *
@ -429,6 +427,7 @@ gimp_statusbar_push (GimpStatusbar *statusbar,
GSList *list; GSList *list;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar)); g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (message != NULL); g_return_if_fail (message != NULL);
context_id = gimp_statusbar_get_context_id (statusbar, context); context_id = gimp_statusbar_get_context_id (statusbar, context);
@ -565,6 +564,7 @@ gimp_statusbar_replace (GimpStatusbar *statusbar,
guint context_id; guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar)); g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (message != NULL); g_return_if_fail (message != NULL);
if (! statusbar->messages) if (! statusbar->messages)
@ -616,6 +616,7 @@ gimp_statusbar_pop (GimpStatusbar *statusbar,
guint context_id; guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar)); g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
context_id = gimp_statusbar_get_context_id (statusbar, context); context_id = gimp_statusbar_get_context_id (statusbar, context);
@ -792,28 +793,16 @@ static guint
gimp_statusbar_get_context_id (GimpStatusbar *statusbar, gimp_statusbar_get_context_id (GimpStatusbar *statusbar,
const gchar *context) const gchar *context)
{ {
gchar *string; guint id = GPOINTER_TO_UINT (g_hash_table_lookup (statusbar->context_ids,
guint *id; context));
g_return_val_if_fail (GIMP_IS_STATUSBAR (statusbar), 0);
g_return_val_if_fail (context != NULL, 0);
/* we need to preserve namespaces on object datas */
string = g_strconcat ("gimp-status-bar-context:", context, NULL);
id = g_object_get_data (G_OBJECT (statusbar), string);
if (! id) if (! id)
{ {
id = g_new (guint, 1); id = statusbar->seq_context_id++;
*id = statusbar->seq_context_id++;
g_object_set_data_full (G_OBJECT (statusbar), string, id, g_free); g_hash_table_insert (statusbar->context_ids,
statusbar->keys = g_slist_prepend (statusbar->keys, string); g_strdup (context), GUINT_TO_POINTER (id));
}
else
{
g_free (string);
} }
return *id; return id;
} }

View File

@ -40,12 +40,12 @@ struct _GimpStatusbar
{ {
GtkHBox parent_instance; GtkHBox parent_instance;
GSList *messages;
GSList *keys;
guint seq_context_id;
GimpDisplayShell *shell; GimpDisplayShell *shell;
GSList *messages;
GHashTable *context_ids;
guint seq_context_id;
gchar cursor_format_str[CURSOR_FORMAT_LENGTH]; gchar cursor_format_str[CURSOR_FORMAT_LENGTH];
gchar length_format_str[CURSOR_FORMAT_LENGTH]; gchar length_format_str[CURSOR_FORMAT_LENGTH];