From dc7efe296da907b6308791125003a7df02d4fc26 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Mon, 23 Mar 2020 17:03:51 +0100 Subject: [PATCH] gstvalue: Optimize list subset some more Avoid going through the double subtract function when comparing anything to a list. Part-of: --- gst/gstvalue.c | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gst/gstvalue.c b/gst/gstvalue.c index 10f539c..2cd4883 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -4303,6 +4303,25 @@ gst_value_is_subset_list_list (const GValue * value1, const GValue * value2) return TRUE; } +static gboolean +gst_value_is_subset_list (const GValue * value1, const GValue * value2) +{ + GstValueList *vlist2 = VALUE_LIST_ARRAY (value2); + gint it2, len2; + + len2 = vlist2->len; + + /* Check whether value1 is within the list */ + for (it2 = 0; it2 < len2; it2++) { + const GValue *child2 = &vlist2->fields[it2]; + if (gst_value_compare (value1, child2) == GST_VALUE_EQUAL) { + return TRUE; + } + } + + return FALSE; +} + /** * gst_value_is_subset: * @value1: a #GValue @@ -4315,6 +4334,9 @@ gst_value_is_subset_list_list (const GValue * value1, const GValue * value2) gboolean gst_value_is_subset (const GValue * value1, const GValue * value2) { + GType type1 = G_VALUE_TYPE (value1); + GType type2 = G_VALUE_TYPE (value2); + /* special case for int/int64 ranges, since we cannot compute the difference for those when they have different steps, and it's actually a lot simpler to compute whether a range @@ -4330,8 +4352,10 @@ gst_value_is_subset (const GValue * value1, const GValue * value2) } else if (GST_VALUE_HOLDS_STRUCTURE (value1) && GST_VALUE_HOLDS_STRUCTURE (value2)) { return gst_value_is_subset_structure_structure (value1, value2); - } else if (GST_VALUE_HOLDS_LIST (value1) && GST_VALUE_HOLDS_LIST (value2)) { - return gst_value_is_subset_list_list (value1, value2); + } else if (type2 == GST_TYPE_LIST) { + if (type1 == GST_TYPE_LIST) + return gst_value_is_subset_list_list (value1, value2); + return gst_value_is_subset_list (value1, value2); } /* -- 2.7.4