value: Consider "1" and "{1}" as equal in gst_value_compare()
authorSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 30 May 2011 09:33:57 +0000 (11:33 +0200)
committerSebastian Dröge <sebastian.droege@collabora.co.uk>
Mon, 30 May 2011 09:33:57 +0000 (11:33 +0200)
Previously this was only done in the is_subset() check but
having it only there brings us into definition-hell where
"1" and "{1}" are subset of each other but not equal.

gst/gststructure.c
gst/gstvalue.c

index 1f3a462..3b2c2e4 100644 (file)
@@ -3107,48 +3107,11 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value,
   GstStructure *superset = user_data;
   GValue subtraction = { 0, };
   const GValue *other;
-  GType ltype;
 
   if (!(other = gst_structure_id_get_value (superset, field_id)))
     /* field is missing in the superset => is subset */
     return TRUE;
 
-  /* Special case: lists and scalar values 
-   * "{ 1 }" and "1" subsets of each other
-   * but not strictly equal */
-  ltype = gst_value_list_get_type ();
-  if (G_VALUE_HOLDS (other, ltype) && !G_VALUE_HOLDS (value, ltype)) {
-    const GValue *elt;
-    gint i, n;
-    gboolean all_equal = TRUE;
-
-    n = gst_value_list_get_size (other);
-    for (i = 0; i < n; i++) {
-      elt = gst_value_list_get_value (other, 0);
-      if (gst_value_compare (elt, value) != GST_VALUE_EQUAL) {
-        all_equal = FALSE;
-        break;
-      }
-    }
-    if (all_equal)
-      return TRUE;
-  } else if (G_VALUE_HOLDS (value, ltype) && !G_VALUE_HOLDS (other, ltype)) {
-    const GValue *elt;
-    gint i, n;
-    gboolean all_equal = TRUE;
-
-    n = gst_value_list_get_size (value);
-    for (i = 0; i < n; i++) {
-      elt = gst_value_list_get_value (value, 0);
-      if (gst_value_compare (elt, other) != GST_VALUE_EQUAL) {
-        all_equal = FALSE;
-        break;
-      }
-    }
-    if (all_equal)
-      return TRUE;
-  }
-
   /* equal values are subset */
   if (gst_value_compare (other, value) == GST_VALUE_EQUAL)
     return TRUE;
index 8baf1e6..3817160 100644 (file)
@@ -3394,10 +3394,28 @@ gint
 gst_value_compare (const GValue * value1, const GValue * value2)
 {
   GstValueCompareFunc compare;
+  GType ltype;
 
   g_return_val_if_fail (G_IS_VALUE (value1), GST_VALUE_LESS_THAN);
   g_return_val_if_fail (G_IS_VALUE (value2), GST_VALUE_GREATER_THAN);
 
+  /* Special case: lists and scalar values 
+   * "{ 1 }" and "1" are equal */
+  ltype = gst_value_list_get_type ();
+  if (G_VALUE_HOLDS (value1, ltype) && !G_VALUE_HOLDS (value2, ltype)
+      && gst_value_list_get_size (value1) == 1) {
+    const GValue *elt;
+
+    elt = gst_value_list_get_value (value1, 0);
+    return gst_value_compare (elt, value2);
+  } else if (G_VALUE_HOLDS (value2, ltype) && !G_VALUE_HOLDS (value1, ltype)
+      && gst_value_list_get_size (value2) == 1) {
+    const GValue *elt;
+
+    elt = gst_value_list_get_value (value2, 0);
+    return gst_value_compare (elt, value1);
+  }
+
   if (G_VALUE_TYPE (value1) != G_VALUE_TYPE (value2))
     return GST_VALUE_UNORDERED;