[glade] GladeWidgetAdaptor: use a direct hash for the adaptor hash table by stuffing the GType into a pointe
- From: Juan Pablo Ugarte <jpu src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glade] GladeWidgetAdaptor: use a direct hash for the adaptor hash table by stuffing the GType into a pointe
- Date: Fri, 20 May 2016 20:26:48 +0000 (UTC)
commit eae2e01f7411aff1592749ad0ced9feb68d9ed18
Author: Juan Pablo Ugarte <juanpablougarte gmail com>
Date: Mon May 16 17:08:52 2016 -0300
GladeWidgetAdaptor: use a direct hash for the adaptor hash table by stuffing the GType into a pointer
with GSIZE_TO_POINTER()
gladeui/glade-widget-adaptor.c | 53 +++++++---------------------------------
1 files changed, 9 insertions(+), 44 deletions(-)
---
diff --git a/gladeui/glade-widget-adaptor.c b/gladeui/glade-widget-adaptor.c
index d9ada45..74917fd 100644
--- a/gladeui/glade-widget-adaptor.c
+++ b/gladeui/glade-widget-adaptor.c
@@ -212,20 +212,6 @@ gwa_create_cursor (GladeWidgetAdaptor *adaptor)
g_object_unref (widget_pixbuf);
}
-
-
-static gboolean
-gwa_gtype_equal (gconstpointer v1, gconstpointer v2)
-{
- return *((const GType *) v1) == *((const GType *) v2);
-}
-
-static guint
-gwa_gtype_hash (gconstpointer v)
-{
- return *(const GType *) v;
-}
-
static gboolean
glade_widget_adaptor_hash_find (gpointer key,
gpointer value,
@@ -1851,7 +1837,7 @@ glade_widget_adaptor_get_signals (GladeWidgetAdaptor *adaptor)
}
static void
-accum_adaptor (GType *type, GladeWidgetAdaptor *adaptor, GList **list)
+accum_adaptor (gpointer key, GladeWidgetAdaptor *adaptor, GList **list)
{
*list = g_list_prepend (*list, adaptor);
}
@@ -1893,11 +1879,10 @@ glade_widget_adaptor_register (GladeWidgetAdaptor *adaptor)
}
if (!adaptor_hash)
- adaptor_hash = g_hash_table_new_full (gwa_gtype_hash, gwa_gtype_equal,
- g_free, g_object_unref);
+ adaptor_hash = g_hash_table_new_full (g_direct_hash, g_direct_equal,
+ NULL, g_object_unref);
- g_hash_table_insert (adaptor_hash,
- g_memdup (&adaptor->priv->type, sizeof (GType)), adaptor);
+ g_hash_table_insert (adaptor_hash, GSIZE_TO_POINTER (adaptor->priv->type), adaptor);
g_signal_emit_by_name (glade_app_get (), "widget-adaptor-registered", adaptor, NULL);
}
@@ -3028,22 +3013,6 @@ glade_widget_adaptor_create_widget_real (gboolean query,
return gwidget;
}
-typedef struct
-{
- const gchar *name;
- GladeWidgetAdaptor *adaptor;
-} GladeAdaptorSearchPair;
-
-
-static void
-search_adaptor_by_name (GType *type,
- GladeWidgetAdaptor *adaptor,
- GladeAdaptorSearchPair *pair)
-{
- if (!strcmp (adaptor->priv->name, pair->name))
- pair->adaptor = adaptor;
-}
-
/**
* glade_widget_adaptor_get_by_name:
* @name: name of the widget class (for instance: GtkButton)
@@ -3054,16 +3023,12 @@ search_adaptor_by_name (GType *type,
GladeWidgetAdaptor *
glade_widget_adaptor_get_by_name (const gchar *name)
{
+ GType type = g_type_from_name (name);
+ if (adaptor_hash && type)
+ return g_hash_table_lookup (adaptor_hash, GSIZE_TO_POINTER (type));
- GladeAdaptorSearchPair pair = { name, NULL };
-
- if (adaptor_hash != NULL)
- {
- g_hash_table_foreach (adaptor_hash,
- (GHFunc) search_adaptor_by_name, &pair);
- }
- return pair.adaptor;
+ return NULL;
}
@@ -3078,7 +3043,7 @@ GladeWidgetAdaptor *
glade_widget_adaptor_get_by_type (GType type)
{
if (adaptor_hash != NULL)
- return g_hash_table_lookup (adaptor_hash, &type);
+ return g_hash_table_lookup (adaptor_hash, GSIZE_TO_POINTER (type));
else
return NULL;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]