From 4530151ad2992e189d26aa7926ec8254bb86f158 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Tim-Philipp=20M=C3=BCller?= Date: Thu, 11 Jun 2009 14:18:03 +0100 Subject: [PATCH] gstvalue: more efficient value table lookup for fundamental types Small micro-optimisation: look up value table for fundamental types via an array dedicated to fundamental types instead of going through a hash table lookup. Since there can be only 255 fundamental types, the table size/efficiency trade-off should be acceptable, esp. since the most commonly-used types are all fundamental types. The size of the table could probably be minimised further if needed by allocating the table dynamically and only expanding it on demand. --- gst/gstvalue.c | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 5d8cabce20..ef647cef9f 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -67,8 +67,14 @@ struct _GstValueSubtractInfo GstValueSubtractFunc func; }; +#define FUNDAMENTAL_TYPE_ID_MAX \ + (G_TYPE_FUNDAMENTAL_MAX >> G_TYPE_FUNDAMENTAL_SHIFT) +#define FUNDAMENTAL_TYPE_ID(type) \ + ((type) >> G_TYPE_FUNDAMENTAL_SHIFT) + static GArray *gst_value_table; static GHashTable *gst_value_hash; +static GstValueTable *gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID_MAX + 1]; static GArray *gst_value_union_funcs; static GArray *gst_value_intersect_funcs; static GArray *gst_value_subtract_funcs; @@ -88,12 +94,18 @@ static gchar *gst_string_unwrap (const gchar * s); static inline GstValueTable * gst_value_hash_lookup_type (GType type) { - return g_hash_table_lookup (gst_value_hash, (gpointer) type); + if (G_LIKELY (G_TYPE_IS_FUNDAMENTAL (type))) + return gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)]; + else + return g_hash_table_lookup (gst_value_hash, (gpointer) type); } static void gst_value_hash_add_type (GType type, const GstValueTable * table) { + if (G_TYPE_IS_FUNDAMENTAL (type)) + gst_value_tables_fundamental[FUNDAMENTAL_TYPE_ID (type)] = (gpointer) table; + g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table); }