caps: simplify code a bit
authorTim-Philipp Müller <tim.muller@collabora.co.uk>
Wed, 8 Sep 2010 17:41:18 +0000 (18:41 +0100)
committerTim-Philipp Müller <tim.muller@collabora.co.uk>
Wed, 8 Sep 2010 17:51:09 +0000 (18:51 +0100)
No need to call g_slist_length() here.

gst/gstcaps.c

index 14f9f74..dd3303e 100644 (file)
@@ -1837,24 +1837,17 @@ gst_caps_structure_simplify (GstStructure ** result,
 
   /* try to subtract to get a real subset */
   if (gst_caps_structure_subtract (&list, simplify, compare)) {
-    switch (g_slist_length (list)) {
-      case 0:
-        *result = NULL;
-        return TRUE;
-      case 1:
-        *result = list->data;
-        g_slist_free (list);
-        return TRUE;
-      default:
-      {
-        GSList *walk;
-
-        for (walk = list; walk; walk = g_slist_next (walk)) {
-          gst_structure_free (walk->data);
-        }
-        g_slist_free (list);
-        break;
-      }
+    if (list == NULL) {         /* no result */
+      *result = NULL;
+      return TRUE;
+    } else if (list->next == NULL) {    /* one result */
+      *result = list->data;
+      g_slist_free (list);
+      return TRUE;
+    } else {                    /* multiple results */
+      g_slist_foreach (list, (GFunc) gst_structure_free, NULL);
+      g_slist_free (list);
+      list = NULL;
     }
   }