mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-18 22:36:33 +00:00
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.
This commit is contained in:
parent
e8bfd88f26
commit
4530151ad2
1 changed files with 13 additions and 1 deletions
|
@ -67,8 +67,14 @@ struct _GstValueSubtractInfo
|
||||||
GstValueSubtractFunc func;
|
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 GArray *gst_value_table;
|
||||||
static GHashTable *gst_value_hash;
|
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_union_funcs;
|
||||||
static GArray *gst_value_intersect_funcs;
|
static GArray *gst_value_intersect_funcs;
|
||||||
static GArray *gst_value_subtract_funcs;
|
static GArray *gst_value_subtract_funcs;
|
||||||
|
@ -88,12 +94,18 @@ static gchar *gst_string_unwrap (const gchar * s);
|
||||||
static inline GstValueTable *
|
static inline GstValueTable *
|
||||||
gst_value_hash_lookup_type (GType type)
|
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
|
static void
|
||||||
gst_value_hash_add_type (GType type, const GstValueTable * table)
|
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);
|
g_hash_table_insert (gst_value_hash, (gpointer) type, (gpointer) table);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue