gst/: Use _CAST macros to avoid unneeded type checking.
authorWim Taymans <wim.taymans@gmail.com>
Mon, 12 Jun 2006 09:17:44 +0000 (09:17 +0000)
committerWim Taymans <wim.taymans@gmail.com>
Mon, 12 Jun 2006 09:17:44 +0000 (09:17 +0000)
Original commit message from CVS:
* gst/gst.c: (gst_debug_help):
* gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
* gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
(gst_plugin_feature_list_free):
* gst/gstregistry.c: (gst_registry_add_plugin),
(gst_registry_add_feature), (gst_registry_plugin_filter),
(gst_registry_feature_filter), (gst_registry_find_plugin),
(gst_registry_find_feature), (gst_registry_get_plugin_list),
(gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
* gst/gstregistryxml.c: (load_feature),
(gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
* gst/gstminiobject.c: (gst_mini_object_unref),
(gst_mini_object_replace), (gst_value_mini_object_free),
(gst_value_mini_object_copy):
Use _CAST macros to avoid unneeded type checking.
Added some more G_UNLIKELY.

ChangeLog
gst/gst.c
gst/gstminiobject.c
gst/gstplugin.c
gst/gstpluginfeature.c
gst/gstregistry.c
gst/gstregistryxml.c

index cc86faf..b29bbb3 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,24 @@
 2006-06-12  Wim Taymans  <wim@fluendo.com>
 
+       * gst/gst.c: (gst_debug_help):
+       * gst/gstplugin.c: (gst_plugin_finalize), (gst_plugin_list_free):
+       * gst/gstpluginfeature.c: (gst_plugin_feature_finalize),
+       (gst_plugin_feature_list_free):
+       * gst/gstregistry.c: (gst_registry_add_plugin),
+       (gst_registry_add_feature), (gst_registry_plugin_filter),
+       (gst_registry_feature_filter), (gst_registry_find_plugin),
+       (gst_registry_find_feature), (gst_registry_get_plugin_list),
+       (gst_registry_lookup_feature_locked), (gst_registry_lookup_locked):
+       * gst/gstregistryxml.c: (load_feature),
+       (gst_registry_xml_read_cache), (gst_registry_xml_write_cache):
+       * gst/gstminiobject.c: (gst_mini_object_unref),
+       (gst_mini_object_replace), (gst_value_mini_object_free),
+       (gst_value_mini_object_copy):
+       Use _CAST macros to avoid unneeded type checking.
+       Added some more G_UNLIKELY.
+
+2006-06-12  Wim Taymans  <wim@fluendo.com>
+
        * gst/gstbuffer.h:
        Avoid unneeded type checking.
        API: GST_BUFFER_IS_DISCONT
index 6a31275..a3b5c34 100644 (file)
--- a/gst/gst.c
+++ b/gst/gst.c
@@ -772,7 +772,7 @@ gst_debug_help (void)
 
   /* FIXME this is gross.  why don't debug have categories PluginFeatures? */
   for (g = list2; g; g = g_list_next (g)) {
-    GstPlugin *plugin = GST_PLUGIN (g->data);
+    GstPlugin *plugin = GST_PLUGIN_CAST (g->data);
 
     gst_plugin_load (plugin);
   }
index 660d4c8..0d527f6 100644 (file)
@@ -300,7 +300,7 @@ gst_mini_object_unref (GstMiniObject * mini_object)
       GST_MINI_OBJECT_REFCOUNT_VALUE (mini_object) - 1);
 #endif
 
-  if (g_atomic_int_dec_and_test (&mini_object->refcount)) {
+  if (G_UNLIKELY (g_atomic_int_dec_and_test (&mini_object->refcount))) {
     gst_mini_object_free (mini_object);
   }
 }
@@ -319,6 +319,12 @@ gst_mini_object_replace (GstMiniObject ** olddata, GstMiniObject * newdata)
 {
   GstMiniObject *olddata_val;
 
+#ifdef DEBUG_REFCOUNT
+  GST_CAT_LOG (GST_CAT_REFCOUNTING, "replace %p (%d) with %p (%d)",
+      *olddata, *olddata ? (*olddata)->refcount : 0,
+      newdata, newdata ? newdata->refcount : 0);
+#endif
+
   if (newdata)
     gst_mini_object_ref (newdata);
 
@@ -341,7 +347,7 @@ static void
 gst_value_mini_object_free (GValue * value)
 {
   if (value->data[0].v_pointer) {
-    gst_mini_object_unref (GST_MINI_OBJECT (value->data[0].v_pointer));
+    gst_mini_object_unref (GST_MINI_OBJECT_CAST (value->data[0].v_pointer));
   }
 }
 
@@ -350,7 +356,8 @@ gst_value_mini_object_copy (const GValue * src_value, GValue * dest_value)
 {
   if (src_value->data[0].v_pointer) {
     dest_value->data[0].v_pointer =
-        gst_mini_object_ref (GST_MINI_OBJECT (src_value->data[0].v_pointer));
+        gst_mini_object_ref (GST_MINI_OBJECT_CAST (src_value->data[0].
+            v_pointer));
   } else {
     dest_value->data[0].v_pointer = NULL;
   }
index 5981ec8..e2425f0 100644 (file)
@@ -124,7 +124,7 @@ gst_plugin_init (GstPlugin * plugin)
 static void
 gst_plugin_finalize (GObject * object)
 {
-  GstPlugin *plugin = GST_PLUGIN (object);
+  GstPlugin *plugin = GST_PLUGIN_CAST (object);
   GstRegistry *registry = gst_registry_get_default ();
   GList *g;
 
@@ -935,7 +935,7 @@ gst_plugin_list_free (GList * list)
   GList *g;
 
   for (g = list; g; g = g->next) {
-    gst_object_unref (GST_PLUGIN (g->data));
+    gst_object_unref (GST_PLUGIN_CAST (g->data));
   }
   g_list_free (list);
 }
index 737fcb3..cc35e5d 100644 (file)
@@ -66,7 +66,7 @@ gst_plugin_feature_init (GstPluginFeature * feature)
 static void
 gst_plugin_feature_finalize (GObject * object)
 {
-  GstPluginFeature *feature = GST_PLUGIN_FEATURE (object);
+  GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (object);
 
   GST_DEBUG ("finalizing feature %p: '%s'", feature,
       GST_PLUGIN_FEATURE_NAME (feature));
@@ -252,7 +252,7 @@ gst_plugin_feature_list_free (GList * list)
   GList *g;
 
   for (g = list; g; g = g->next) {
-    GstPluginFeature *feature = GST_PLUGIN_FEATURE (g->data);
+    GstPluginFeature *feature = GST_PLUGIN_FEATURE_CAST (g->data);
 
     gst_object_unref (feature);
   }
index 0d791c0..6469963 100644 (file)
@@ -314,7 +314,7 @@ gst_registry_add_plugin (GstRegistry * registry, GstPlugin * plugin)
 
   GST_OBJECT_LOCK (registry);
   existing_plugin = gst_registry_lookup_locked (registry, plugin->filename);
-  if (existing_plugin) {
+  if (G_UNLIKELY (existing_plugin)) {
     GST_DEBUG_OBJECT (registry,
         "Replacing existing plugin %p with new plugin %p for filename \"%s\"",
         existing_plugin, plugin, GST_STR_NULL (plugin->filename));
@@ -385,7 +385,7 @@ gst_registry_add_feature (GstRegistry * registry, GstPluginFeature * feature)
   GST_OBJECT_LOCK (registry);
   existing_feature = gst_registry_lookup_feature_locked (registry,
       feature->name);
-  if (existing_feature) {
+  if (G_UNLIKELY (existing_feature)) {
     GST_DEBUG_OBJECT (registry, "Replacing existing feature %p (%s)",
         existing_feature, feature->name);
     registry->features = g_list_remove (registry->features, existing_feature);
@@ -461,7 +461,7 @@ gst_registry_plugin_filter (GstRegistry * registry,
   list = gst_filter_run (registry->plugins, (GstFilterFunc) filter, first,
       user_data);
   for (g = list; g; g = g->next) {
-    gst_object_ref (GST_PLUGIN (g->data));
+    gst_object_ref (GST_PLUGIN_CAST (g->data));
   }
   GST_OBJECT_UNLOCK (registry);
 
@@ -497,7 +497,7 @@ gst_registry_feature_filter (GstRegistry * registry,
   list = gst_filter_run (registry->features, (GstFilterFunc) filter, first,
       user_data);
   for (g = list; g; g = g->next) {
-    gst_object_ref (GST_PLUGIN_FEATURE (g->data));
+    gst_object_ref (GST_PLUGIN_FEATURE_CAST (g->data));
   }
   GST_OBJECT_UNLOCK (registry);
 
@@ -529,7 +529,7 @@ gst_registry_find_plugin (GstRegistry * registry, const gchar * name)
   walk = gst_registry_plugin_filter (registry,
       (GstPluginFilter) gst_plugin_name_filter, TRUE, (gpointer) name);
   if (walk) {
-    result = GST_PLUGIN (walk->data);
+    result = GST_PLUGIN_CAST (walk->data);
 
     gst_object_ref (result);
     gst_plugin_list_free (walk);
@@ -571,7 +571,7 @@ gst_registry_find_feature (GstRegistry * registry, const gchar * name,
       TRUE, &data);
 
   if (walk) {
-    feature = GST_PLUGIN_FEATURE (walk->data);
+    feature = GST_PLUGIN_FEATURE_CAST (walk->data);
 
     gst_object_ref (feature);
     gst_plugin_feature_list_free (walk);
@@ -630,7 +630,7 @@ gst_registry_get_plugin_list (GstRegistry * registry)
   GST_OBJECT_LOCK (registry);
   list = g_list_copy (registry->plugins);
   for (g = list; g; g = g->next) {
-    gst_object_ref (GST_PLUGIN (g->data));
+    gst_object_ref (GST_PLUGIN_CAST (g->data));
   }
   GST_OBJECT_UNLOCK (registry);
 
@@ -643,11 +643,11 @@ gst_registry_lookup_feature_locked (GstRegistry * registry, const char *name)
   GList *g;
   GstPluginFeature *feature;
 
-  if (name == NULL)
+  if (G_UNLIKELY (name == NULL))
     return NULL;
 
   for (g = registry->features; g; g = g_list_next (g)) {
-    feature = GST_PLUGIN_FEATURE (g->data);
+    feature = GST_PLUGIN_FEATURE_CAST (g->data);
     if (feature->name && strcmp (name, feature->name) == 0) {
       return feature;
     }
@@ -692,12 +692,12 @@ gst_registry_lookup_locked (GstRegistry * registry, const char *filename)
   GstPlugin *plugin;
   gchar *basename;
 
-  if (filename == NULL)
+  if (G_UNLIKELY (filename == NULL))
     return NULL;
 
   basename = g_path_get_basename (filename);
   for (g = registry->plugins; g; g = g_list_next (g)) {
-    plugin = GST_PLUGIN (g->data);
+    plugin = GST_PLUGIN_CAST (g->data);
     if (plugin->basename && strcmp (basename, plugin->basename) == 0) {
       g_free (basename);
       return plugin;
index 40d925d..4fbf5af 100644 (file)
@@ -284,10 +284,11 @@ load_feature (xmlTextReaderPtr reader)
 
       if (g_str_equal (tag, "name"))
         read_string (reader, &feature->name, FALSE);
-      if (g_str_equal (tag, "rank"))
+      else if (g_str_equal (tag, "rank"))
         read_uint (reader, &feature->rank);
+
       if (GST_IS_ELEMENT_FACTORY (feature)) {
-        GstElementFactory *factory = GST_ELEMENT_FACTORY (feature);
+        GstElementFactory *factory = GST_ELEMENT_FACTORY_CAST (feature);
 
         if (g_str_equal (tag, "longname")) {
           int ret;
@@ -544,7 +545,8 @@ gst_registry_xml_read_cache (GstRegistry * registry, const char *location)
             GST_DEBUG ("adding plugin %s", plugin->desc.name);
             gst_registry_add_plugin (registry, plugin);
             for (g = feature_list; g; g = g_list_next (g)) {
-              gst_registry_add_feature (registry, GST_PLUGIN_FEATURE (g->data));
+              gst_registry_add_feature (registry,
+                  GST_PLUGIN_FEATURE_CAST (g->data));
             }
             g_list_free (feature_list);
           }
@@ -853,7 +855,7 @@ gst_registry_xml_write_cache (GstRegistry * registry, const char *location)
 
   for (walk = g_list_last (registry->plugins); walk;
       walk = g_list_previous (walk)) {
-    GstPlugin *plugin = GST_PLUGIN (walk->data);
+    GstPlugin *plugin = GST_PLUGIN_CAST (walk->data);
 
     if (!plugin->filename)
       continue;