gstvalue: quicker version of intersection when we do not need the result

https://bugzilla.gnome.org/show_bug.cgi?id=662777
This commit is contained in:
Vincent Penquerc'h 2011-10-27 12:24:13 +01:00
parent d9901a6288
commit b37d06aed8
2 changed files with 69 additions and 30 deletions

View file

@ -3059,10 +3059,7 @@ gst_caps_structure_can_intersect_field (GQuark id, const GValue * val1,
if (eq == GST_VALUE_UNORDERED) {
/* we need to try interseting */
GValue dest_value = { 0 };
if (gst_value_intersect (&dest_value, val1, val2)) {
g_value_unset (&dest_value);
} else {
if (!gst_value_intersect (NULL, val1, val2)) {
return FALSE;
}
} else if (eq != GST_VALUE_EQUAL) {

View file

@ -2602,6 +2602,7 @@ gst_value_intersect_int_int_range (GValue * dest, const GValue * src1,
{
if (src2->data[0].v_int <= src1->data[0].v_int &&
src2->data[1].v_int >= src1->data[0].v_int) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2620,13 +2621,17 @@ gst_value_intersect_int_range_int_range (GValue * dest, const GValue * src1,
max = MIN (src1->data[1].v_int, src2->data[1].v_int);
if (min < max) {
if (dest) {
g_value_init (dest, GST_TYPE_INT_RANGE);
gst_value_set_int_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
if (dest) {
g_value_init (dest, G_TYPE_INT);
g_value_set_int (dest, min);
}
return TRUE;
}
@ -2639,6 +2644,7 @@ gst_value_intersect_int64_int64_range (GValue * dest, const GValue * src1,
{
if (src2->data[0].v_int64 <= src1->data[0].v_int64 &&
src2->data[1].v_int64 >= src1->data[0].v_int64) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2657,13 +2663,17 @@ gst_value_intersect_int64_range_int64_range (GValue * dest, const GValue * src1,
max = MIN (src1->data[1].v_int64, src2->data[1].v_int64);
if (min < max) {
if (dest) {
g_value_init (dest, GST_TYPE_INT64_RANGE);
gst_value_set_int64_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
if (dest) {
g_value_init (dest, G_TYPE_INT64);
g_value_set_int64 (dest, min);
}
return TRUE;
}
@ -2676,6 +2686,7 @@ gst_value_intersect_double_double_range (GValue * dest, const GValue * src1,
{
if (src2->data[0].v_double <= src1->data[0].v_double &&
src2->data[1].v_double >= src1->data[0].v_double) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2694,13 +2705,17 @@ gst_value_intersect_double_range_double_range (GValue * dest,
max = MIN (src1->data[1].v_double, src2->data[1].v_double);
if (min < max) {
if (dest) {
g_value_init (dest, GST_TYPE_DOUBLE_RANGE);
gst_value_set_double_range (dest, min, max);
}
return TRUE;
}
if (min == max) {
if (dest) {
g_value_init (dest, G_TYPE_DOUBLE);
g_value_set_int (dest, (int) min);
}
return TRUE;
}
@ -2719,6 +2734,15 @@ gst_value_intersect_list (GValue * dest, const GValue * value1,
for (i = 0; i < size; i++) {
const GValue *cur = VALUE_LIST_GET_VALUE (value1, i);
/* quicker version when we don't need the resulting set */
if (!dest) {
if (gst_value_intersect (NULL, cur, value2)) {
ret = TRUE;
break;
}
continue;
}
if (gst_value_intersect (&intersection, cur, value2)) {
/* append value */
if (!ret) {
@ -2753,6 +2777,18 @@ gst_value_intersect_array (GValue * dest, const GValue * src1,
size = gst_value_array_get_size (src1);
if (size != gst_value_array_get_size (src2))
return FALSE;
/* quicker value when we don't need the resulting set */
if (!dest) {
for (n = 0; n < size; n++) {
if (!gst_value_intersect (NULL, gst_value_array_get_value (src1, n),
gst_value_array_get_value (src2, n))) {
return FALSE;
}
}
return TRUE;
}
g_value_init (dest, GST_TYPE_ARRAY);
for (n = 0; n < size; n++) {
@ -2787,6 +2823,7 @@ gst_value_intersect_fraction_fraction_range (GValue * dest, const GValue * src1,
if ((res1 == GST_VALUE_EQUAL || res1 == GST_VALUE_LESS_THAN) &&
(res2 == GST_VALUE_EQUAL || res2 == GST_VALUE_GREATER_THAN)) {
if (dest)
gst_value_init_and_copy (dest, src1);
return TRUE;
}
@ -2829,13 +2866,16 @@ gst_value_intersect_fraction_range_fraction_range (GValue * dest,
res = gst_value_compare_with_func (min, max, compare);
g_return_val_if_fail (res != GST_VALUE_UNORDERED, FALSE);
if (res == GST_VALUE_LESS_THAN) {
if (dest) {
g_value_init (dest, GST_TYPE_FRACTION_RANGE);
vals1 = dest->data[0].v_pointer;
g_value_copy (min, &vals1[0]);
g_value_copy (max, &vals1[1]);
}
return TRUE;
}
if (res == GST_VALUE_EQUAL) {
if (dest)
gst_value_init_and_copy (dest, min);
return TRUE;
}
@ -3649,14 +3689,14 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2)
/**
* gst_value_intersect:
* @dest: (out caller-allocates): a uninitialized #GValue that will hold the calculated
* intersection value
* intersection value. May be NULL if the resulting set if not needed.
* @value1: a value to intersect
* @value2: another value to intersect
*
* Calculates the intersection of two values. If the values have
* a non-empty intersection, the value representing the intersection
* is placed in @dest. If the intersection is non-empty, @dest is
* not modified.
* is placed in @dest, unless NULL. If the intersection is non-empty,
* @dest is not modified.
*
* Returns: TRUE if the intersection is non-empty
*/
@ -3668,7 +3708,6 @@ gst_value_intersect (GValue * dest, const GValue * value1,
guint i, len;
GType ltype, type1, type2;
g_return_val_if_fail (dest != NULL, FALSE);
g_return_val_if_fail (G_IS_VALUE (value1), FALSE);
g_return_val_if_fail (G_IS_VALUE (value2), FALSE);
@ -3681,6 +3720,7 @@ gst_value_intersect (GValue * dest, const GValue * value1,
return gst_value_intersect_list (dest, value2, value1);
if (gst_value_compare (value1, value2) == GST_VALUE_EQUAL) {
if (dest)
gst_value_init_and_copy (dest, value1);
return TRUE;
}
@ -3702,6 +3742,8 @@ gst_value_intersect (GValue * dest, const GValue * value1,
return FALSE;
}
/**
* gst_value_register_intersect_func:
* @type1: the first type to intersect