From 6c621460313ae440fe12eab436a55d9487b01393 Mon Sep 17 00:00:00 2001 From: Wim Taymans Date: Thu, 4 Apr 2013 17:59:10 +0200 Subject: [PATCH] structure: simplify is_subset check Iterate over the fields of the superset instead of those of the subset. This way we can check the presence of the subset field and do the subset check in one iteration. --- gst/gststructure.c | 30 ++++++++---------------------- 1 file changed, 8 insertions(+), 22 deletions(-) diff --git a/gst/gststructure.c b/gst/gststructure.c index d39e03aee9..06d7f0d5b2 100644 --- a/gst/gststructure.c +++ b/gst/gststructure.c @@ -3171,27 +3171,18 @@ gst_structure_can_intersect (const GstStructure * struct1, } static gboolean -gst_caps_structure_has_field (GQuark field_id, const GValue * value, +gst_caps_structure_is_superset_field (GQuark field_id, const GValue * value, gpointer user_data) { GstStructure *subset = user_data; - - return gst_structure_id_get_value (subset, field_id) != NULL; -} - -static gboolean -gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value, - gpointer user_data) -{ - GstStructure *superset = user_data; const GValue *other; int comparison; - if (!(other = gst_structure_id_get_value (superset, field_id))) - /* field is missing in the superset => is subset */ - return TRUE; + if (!(other = gst_structure_id_get_value (subset, field_id))) + /* field is missing in the subset => no subset */ + return FALSE; - comparison = gst_value_compare (other, value); + comparison = gst_value_compare (value, other); /* equal values are subset */ if (comparison == GST_VALUE_EQUAL) @@ -3201,7 +3192,7 @@ gst_caps_structure_is_subset_field (GQuark field_id, const GValue * value, if (comparison != GST_VALUE_UNORDERED) return FALSE; - return gst_value_is_subset (value, other); + return gst_value_is_subset (other, value); } /** @@ -3223,13 +3214,8 @@ gst_structure_is_subset (const GstStructure * subset, (gst_structure_n_fields (superset) > gst_structure_n_fields (subset))) return FALSE; - /* The subset must have all fields that are in superset */ - if (!gst_structure_foreach ((GstStructure *) superset, - gst_caps_structure_has_field, (gpointer) subset)) - return FALSE; - - return gst_structure_foreach ((GstStructure *) subset, - gst_caps_structure_is_subset_field, (gpointer) superset); + return gst_structure_foreach ((GstStructure *) superset, + gst_caps_structure_is_superset_field, (gpointer) subset); }