gstvalue: No longer store same-type intersection functions in table

The intersection function table is a legacy of 2005, when one could
register random intersection functions. This is no longer the case.

The only place where that table was used was:

* `gst_value_can_intersect()`, where it was already only used for identical
GType
* `gst_value_intersect()`, where the table iteration was insanely expensive

Instead this patch:
* Only stored intersection functions for *different* types (of which there are
only 4)
* Make gst_value_intersect directly call the same-type intersection functions
and only use the table if ever it doesn't match.

Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/454>
This commit is contained in:
Edward Hervey 2020-05-01 15:03:55 +02:00 committed by Edward Hervey
parent 5e553b8cce
commit 841fa7062e

View file

@ -6061,7 +6061,8 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2)
return TRUE; return TRUE;
} }
/* check registered intersect functions */ /* check registered intersect functions (only different gtype are checked at
* this point) */
len = gst_value_intersect_funcs->len; len = gst_value_intersect_funcs->len;
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
intersect_info = &g_array_index (gst_value_intersect_funcs, intersect_info = &g_array_index (gst_value_intersect_funcs,
@ -6116,15 +6117,36 @@ gst_value_intersect (GValue * dest, const GValue * value1,
return TRUE; return TRUE;
} }
len = gst_value_intersect_funcs->len; if (type1 == type2) {
for (i = 0; i < len; i++) { /* Equal type comparison */
intersect_info = &g_array_index (gst_value_intersect_funcs, if (type1 == GST_TYPE_INT_RANGE)
GstValueIntersectInfo, i); return gst_value_intersect_int_range_int_range (dest, value1, value2);
if (intersect_info->type1 == type1 && intersect_info->type2 == type2) { if (type1 == GST_TYPE_INT64_RANGE)
return intersect_info->func (dest, value1, value2); return gst_value_intersect_int64_range_int64_range (dest, value1, value2);
} if (type1 == GST_TYPE_DOUBLE_RANGE)
if (intersect_info->type1 == type2 && intersect_info->type2 == type1) { return gst_value_intersect_double_range_double_range (dest, value1,
return intersect_info->func (dest, value2, value1); value2);
if (type1 == GST_TYPE_ARRAY)
return gst_value_intersect_array (dest, value1, value2);
if (type1 == GST_TYPE_FRACTION_RANGE)
return gst_value_intersect_fraction_range_fraction_range (dest, value1,
value2);
if (type1 == GST_TYPE_FLAG_SET)
return gst_value_intersect_flagset_flagset (dest, value1, value2);
if (type1 == GST_TYPE_STRUCTURE)
return gst_value_intersect_structure_structure (dest, value1, value2);
} else {
/* Different type comparison */
len = gst_value_intersect_funcs->len;
for (i = 0; i < len; i++) {
intersect_info = &g_array_index (gst_value_intersect_funcs,
GstValueIntersectInfo, i);
if (intersect_info->type1 == type1 && intersect_info->type2 == type2) {
return intersect_info->func (dest, value1, value2);
}
if (intersect_info->type1 == type2 && intersect_info->type2 == type1) {
return intersect_info->func (dest, value2, value1);
}
} }
} }
@ -7785,7 +7807,7 @@ G_STMT_START { \
static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 40; static const gint GST_VALUE_TABLE_DEFAULT_SIZE = 40;
static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 8; static const gint GST_VALUE_UNION_TABLE_DEFAULT_SIZE = 8;
static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 16; static const gint GST_VALUE_INTERSECT_TABLE_DEFAULT_SIZE = 4;
static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 16; static const gint GST_VALUE_SUBTRACT_TABLE_DEFAULT_SIZE = 16;
void void
@ -7904,29 +7926,17 @@ _priv_gst_value_initialize (void)
g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET, g_value_register_transform_func (G_TYPE_STRING, GST_TYPE_FLAG_SET,
gst_value_transform_string_flagset); gst_value_transform_string_flagset);
/* Only register intersection functions for *different* types.
* Identical type intersection should be specified directly in
* gst_value_intersect() */
gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE, gst_value_register_intersect_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
gst_value_intersect_int_int_range); gst_value_intersect_int_int_range);
gst_value_register_intersect_func (GST_TYPE_INT_RANGE, GST_TYPE_INT_RANGE,
gst_value_intersect_int_range_int_range);
gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE, gst_value_register_intersect_func (G_TYPE_INT64, GST_TYPE_INT64_RANGE,
gst_value_intersect_int64_int64_range); gst_value_intersect_int64_int64_range);
gst_value_register_intersect_func (GST_TYPE_INT64_RANGE,
GST_TYPE_INT64_RANGE, gst_value_intersect_int64_range_int64_range);
gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE, gst_value_register_intersect_func (G_TYPE_DOUBLE, GST_TYPE_DOUBLE_RANGE,
gst_value_intersect_double_double_range); gst_value_intersect_double_double_range);
gst_value_register_intersect_func (GST_TYPE_DOUBLE_RANGE,
GST_TYPE_DOUBLE_RANGE, gst_value_intersect_double_range_double_range);
gst_value_register_intersect_func (GST_TYPE_ARRAY, GST_TYPE_ARRAY,
gst_value_intersect_array);
gst_value_register_intersect_func (GST_TYPE_FRACTION, gst_value_register_intersect_func (GST_TYPE_FRACTION,
GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range); GST_TYPE_FRACTION_RANGE, gst_value_intersect_fraction_fraction_range);
gst_value_register_intersect_func (GST_TYPE_FRACTION_RANGE,
GST_TYPE_FRACTION_RANGE,
gst_value_intersect_fraction_range_fraction_range);
gst_value_register_intersect_func (GST_TYPE_FLAG_SET, GST_TYPE_FLAG_SET,
gst_value_intersect_flagset_flagset);
gst_value_register_intersect_func (GST_TYPE_STRUCTURE, GST_TYPE_STRUCTURE,
gst_value_intersect_structure_structure);
gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE, gst_value_register_subtract_func (G_TYPE_INT, GST_TYPE_INT_RANGE,
gst_value_subtract_int_int_range); gst_value_subtract_int_int_range);