gst/gstregistry.*: Speed up gst_registry_lookup_feature_locked() by using a hashmap.

Original commit message from CVS:
* gst/gstregistry.c: (gst_registry_init), (gst_registry_finalize),
(gst_registry_remove_features_for_plugin_unlocked),
(gst_registry_add_feature), (gst_registry_remove_feature),
(gst_registry_lookup_feature_locked):
* gst/gstregistry.h:
Speed up gst_registry_lookup_feature_locked() by using a hashmap.
Fixes #459501.
This commit is contained in:
Stefan Kost 2007-07-23 11:42:12 +00:00
parent 163242c644
commit a6b990938e
3 changed files with 23 additions and 18 deletions

View file

@ -1,3 +1,13 @@
2007-07-23 Stefan Kost <ensonic@users.sf.net>
* gst/gstregistry.c: (gst_registry_init), (gst_registry_finalize),
(gst_registry_remove_features_for_plugin_unlocked),
(gst_registry_add_feature), (gst_registry_remove_feature),
(gst_registry_lookup_feature_locked):
* gst/gstregistry.h:
Speed up gst_registry_lookup_feature_locked() by using a hashmap.
Fixes #459501.
2007-07-23 Stefan Kost <ensonic@users.sf.net>
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),

View file

@ -175,7 +175,7 @@ gst_registry_class_init (GstRegistryClass * klass)
static void
gst_registry_init (GstRegistry * registry)
{
/* do nothing, needed because of G_DEFINE_TYPE */
registry->feature_hash = g_hash_table_new (g_str_hash, g_str_equal);
}
static void
@ -218,6 +218,8 @@ gst_registry_finalize (GObject * object)
}
g_list_free (features);
g_hash_table_destroy (registry->feature_hash);
registry->feature_hash = NULL;
G_OBJECT_CLASS (parent_class)->finalize (object);
}
@ -383,6 +385,7 @@ gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
gst_plugin_get_name (plugin));
registry->features = g_list_delete_link (registry->features, f);
g_hash_table_remove (registry->feature_hash, feature->name);
gst_object_unref (feature);
}
f = next;
@ -440,15 +443,17 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
existing_feature = gst_registry_lookup_feature_locked (registry,
feature->name);
if (G_UNLIKELY (existing_feature)) {
GST_DEBUG_OBJECT (registry, "Replacing existing feature %p (%s)",
GST_DEBUG_OBJECT (registry, "replacing existing feature %p (%s)",
existing_feature, feature->name);
registry->features = g_list_remove (registry->features, existing_feature);
/* no need to remove from feature_hash, as insert will replace the value */
gst_object_unref (existing_feature);
}
GST_DEBUG_OBJECT (registry, "adding feature %p (%s)", feature, feature->name);
registry->features = g_list_prepend (registry->features, feature);
g_hash_table_insert (registry->feature_hash, feature->name, feature);
gst_object_ref (feature);
gst_object_sink (feature);
@ -481,6 +486,7 @@ gst_registry_remove_feature (GstRegistry * registry, GstPluginFeature * feature)
GST_OBJECT_LOCK (registry);
registry->features = g_list_remove (registry->features, feature);
g_hash_table_remove (registry->feature_hash, feature->name);
GST_OBJECT_UNLOCK (registry);
gst_object_unref (feature);
}
@ -694,21 +700,10 @@ gst_registry_get_plugin_list (GstRegistry * registry)
static GstPluginFeature *
gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
{
GList *g;
GstPluginFeature *feature;
if (G_UNLIKELY (name == NULL))
return NULL;
/* FIXME: use GTree speed up lookups */
for (g = registry->features; g; g = g_list_next (g)) {
feature = GST_PLUGIN_FEATURE_CAST (g->data);
if (feature->name && strcmp (name, feature->name) == 0) {
return feature;
}
}
return NULL;
return g_hash_table_lookup (registry->feature_hash, name);
}
/**

View file

@ -50,9 +50,6 @@ struct _GstRegistry {
GstObject object;
/*< private >*/
/* FIXME: shouldn't we use GTree for these to speedup
* gst_registry_lookup_feature_locked(), gst_registry_lookup_locked()
*/
GList *plugins;
GList *features;
@ -61,8 +58,11 @@ struct _GstRegistry {
/* FIXME move these elsewhere */
int cache_file;
/* hash to speedup _lookup_feature_locked() */
GHashTable *feature_hash;
/*< private >*/
gpointer _gst_reserved[GST_PADDING];
gpointer _gst_reserved[GST_PADDING-1];
};
struct _GstRegistryClass {