From 32248a9b852bcb568a5b642299ecc8e5bf48ea13 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sebastian=20Dr=C3=B6ge?= Date: Fri, 27 May 2011 12:45:59 +0200 Subject: [PATCH] caps: Optimize gst_caps_is_subset() ..and as a result gst_caps_is_equal() and others. This now only checks if for every subset structure there is a superset structure in the superset caps. Previously we were subtracting one from another, creating completely new caps and then even simplified them. The new implemention now is about 1.27 times faster. --- gst/gstcaps.c | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index 3010d29d2e..9c98fce0f3 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1133,8 +1133,9 @@ gst_caps_is_always_compatible (const GstCaps * caps1, const GstCaps * caps2) gboolean gst_caps_is_subset (const GstCaps * subset, const GstCaps * superset) { - GstCaps *caps; - gboolean ret; + GstStructure *s1, *s2; + gboolean ret = TRUE; + gint i, j; g_return_val_if_fail (subset != NULL, FALSE); g_return_val_if_fail (superset != NULL, FALSE); @@ -1144,9 +1145,24 @@ gst_caps_is_subset (const GstCaps * subset, const GstCaps * superset) if (CAPS_IS_ANY (subset) || CAPS_IS_EMPTY (superset)) return FALSE; - caps = gst_caps_subtract (subset, superset); - ret = CAPS_IS_EMPTY_SIMPLE (caps); - gst_caps_unref (caps); + for (i = subset->structs->len - 1; i >= 0; i--) { + for (j = superset->structs->len - 1; j >= 0; j--) { + s1 = gst_caps_get_structure_unchecked (subset, i); + s2 = gst_caps_get_structure_unchecked (superset, j); + if (gst_caps_structure_is_subset (s2, s1)) { + /* If we found a superset, continue with the next + * subset structure */ + break; + } + } + /* If we found no superset for this subset structure + * we return FALSE immediately */ + if (j == -1) { + ret = FALSE; + break; + } + } + return ret; }