From 1d0bda8005066f481ff5b243dccb983306023410 Mon Sep 17 00:00:00 2001 From: Edward Hervey Date: Fri, 17 Apr 2020 17:12:10 +0200 Subject: [PATCH] caps: Unify common checks for intersections Regardless of the intersect method chosen, migrate the same checks up into the calling function. Same result, just less code. Part-of: --- gst/gstcaps.c | 46 ++++++++++++++++------------------------------ 1 file changed, 16 insertions(+), 30 deletions(-) diff --git a/gst/gstcaps.c b/gst/gstcaps.c index aa4a34d900..2bbb5ff7fa 100644 --- a/gst/gstcaps.c +++ b/gst/gstcaps.c @@ -1620,21 +1620,6 @@ gst_caps_intersect_zig_zag (GstCaps * caps1, GstCaps * caps2) GstCaps *dest; GstStructure *istruct; - /* caps are exactly the same pointers, just copy one caps */ - if (G_UNLIKELY (caps1 == caps2)) - return gst_caps_ref (caps1); - - /* empty caps on either side, return empty */ - if (G_UNLIKELY (CAPS_IS_EMPTY (caps1) || CAPS_IS_EMPTY (caps2))) - return gst_caps_ref (GST_CAPS_NONE); - - /* one of the caps is any, just copy the other caps */ - if (G_UNLIKELY (CAPS_IS_ANY (caps1))) - return gst_caps_ref (caps2); - - if (G_UNLIKELY (CAPS_IS_ANY (caps2))) - return gst_caps_ref (caps1); - dest = gst_caps_new_empty (); /* run zigzag on top line then right line, this preserves the caps order * much better than a simple loop. @@ -1719,21 +1704,6 @@ gst_caps_intersect_first (GstCaps * caps1, GstCaps * caps2) GstCaps *dest; GstStructure *istruct; - /* caps are exactly the same pointers, just copy one caps */ - if (G_UNLIKELY (caps1 == caps2)) - return gst_caps_ref (caps1); - - /* empty caps on either side, return empty */ - if (G_UNLIKELY (CAPS_IS_EMPTY (caps1) || CAPS_IS_EMPTY (caps2))) - return gst_caps_ref (GST_CAPS_NONE); - - /* one of the caps is any, just copy the other caps */ - if (G_UNLIKELY (CAPS_IS_ANY (caps1))) - return gst_caps_ref (caps2); - - if (G_UNLIKELY (CAPS_IS_ANY (caps2))) - return gst_caps_ref (caps1); - dest = gst_caps_new_empty (); len1 = GST_CAPS_LEN (caps1); len2 = GST_CAPS_LEN (caps2); @@ -1785,6 +1755,22 @@ gst_caps_intersect_full (GstCaps * caps1, GstCaps * caps2, g_return_val_if_fail (GST_IS_CAPS (caps1), NULL); g_return_val_if_fail (GST_IS_CAPS (caps2), NULL); + /* Common fast-path */ + /* caps are exactly the same pointers, just copy one caps */ + if (G_UNLIKELY (caps1 == caps2)) + return gst_caps_ref (caps1); + + /* empty caps on either side, return empty */ + if (G_UNLIKELY (CAPS_IS_EMPTY (caps1) || CAPS_IS_EMPTY (caps2))) + return gst_caps_ref (GST_CAPS_NONE); + + /* one of the caps is any, just copy the other caps */ + if (G_UNLIKELY (CAPS_IS_ANY (caps1))) + return gst_caps_ref (caps2); + + if (G_UNLIKELY (CAPS_IS_ANY (caps2))) + return gst_caps_ref (caps1); + switch (mode) { case GST_CAPS_INTERSECT_FIRST: return gst_caps_intersect_first (caps1, caps2);