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>
* 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>

View File

@ -1,5 +1,5 @@
/* The GIMP -- an image manipulation program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
/* The GIMP -- an image manipulation program Copyright (C) 1995
* Spencer Kimball and Peter Mattis
*
* 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
@ -59,7 +59,7 @@ struct _GimpStatusbarMsg
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 *
gimp_statusbar_progress_start (GimpProgress *progress,
@ -97,10 +97,10 @@ G_DEFINE_TYPE_WITH_CODE (GimpStatusbar, gimp_statusbar, GTK_TYPE_HBOX,
static void
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);
object_class->destroy = gimp_statusbar_destroy;
object_class->finalize = gimp_statusbar_finalize;
gtk_widget_class_install_style_property (widget_class,
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");
statusbar->context_ids = g_hash_table_new_full (g_str_hash, g_str_equal,
g_free, NULL);
statusbar->seq_context_id = 1;
statusbar->messages = NULL;
statusbar->keys = NULL;
}
static void
@ -225,7 +226,7 @@ gimp_statusbar_progress_iface_init (GimpProgressInterface *iface)
}
static void
gimp_statusbar_destroy (GtkObject *object)
gimp_statusbar_finalize (GObject *object)
{
GimpStatusbar *statusbar = GIMP_STATUSBAR (object);
GSList *list;
@ -241,13 +242,10 @@ gimp_statusbar_destroy (GtkObject *object)
g_slist_free (statusbar->messages);
statusbar->messages = NULL;
for (list = statusbar->keys; list; list = list->next)
g_free (list->data);
g_hash_table_destroy (statusbar->context_ids);
statusbar->context_ids = NULL;
g_slist_free (statusbar->keys);
statusbar->keys = NULL;
GTK_OBJECT_CLASS (parent_class)->destroy (object);
G_OBJECT_CLASS (parent_class)->finalize (object);
}
static GimpProgress *
@ -429,6 +427,7 @@ gimp_statusbar_push (GimpStatusbar *statusbar,
GSList *list;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (message != NULL);
context_id = gimp_statusbar_get_context_id (statusbar, context);
@ -565,6 +564,7 @@ gimp_statusbar_replace (GimpStatusbar *statusbar,
guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
g_return_if_fail (message != NULL);
if (! statusbar->messages)
@ -616,6 +616,7 @@ gimp_statusbar_pop (GimpStatusbar *statusbar,
guint context_id;
g_return_if_fail (GIMP_IS_STATUSBAR (statusbar));
g_return_if_fail (context != NULL);
context_id = gimp_statusbar_get_context_id (statusbar, context);
@ -792,28 +793,16 @@ static guint
gimp_statusbar_get_context_id (GimpStatusbar *statusbar,
const gchar *context)
{
gchar *string;
guint *id;
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);
guint id = GPOINTER_TO_UINT (g_hash_table_lookup (statusbar->context_ids,
context));
if (! id)
{
id = g_new (guint, 1);
*id = statusbar->seq_context_id++;
g_object_set_data_full (G_OBJECT (statusbar), string, id, g_free);
statusbar->keys = g_slist_prepend (statusbar->keys, string);
}
else
{
g_free (string);
id = statusbar->seq_context_id++;
g_hash_table_insert (statusbar->context_ids,
g_strdup (context), GUINT_TO_POINTER (id));
}
return *id;
return id;
}

View File

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