summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 7090257)
raw | patch | inline | side by side (parent: 7090257)
author | Vincent Penquerc'h <vincent.penquerch@collabora.co.uk> | |
Thu, 27 Oct 2011 09:35:53 +0000 (10:35 +0100) | ||
committer | Vincent Penquerc'h <vincent.penquerch@collabora.co.uk> | |
Mon, 7 Nov 2011 15:16:52 +0000 (15:16 +0000) |
When we do not care about the actual resulting set,
but only whether it is empty of not, we can skip a fair bit
of GValue juggling.
Add a function that does so, since we cannot just pass NULL
to the existing API as it may be part of the API contract.
https://bugzilla.gnome.org/show_bug.cgi?id=662777
but only whether it is empty of not, we can skip a fair bit
of GValue juggling.
Add a function that does so, since we cannot just pass NULL
to the existing API as it may be part of the API contract.
https://bugzilla.gnome.org/show_bug.cgi?id=662777
gst/gststructure.c | patch | blob | history | |
gst/gstvalue.c | patch | blob | history |
diff --git a/gst/gststructure.c b/gst/gststructure.c
index a2547970fd247179d5cacf8db0b2d389a5b131e3..f06049c9ca050ceb0a1384bc2bdc92492e545203 100644 (file)
--- a/gst/gststructure.c
+++ b/gst/gststructure.c
gpointer user_data)
{
GstStructure *superset = user_data;
- GValue subtraction = { 0, };
const GValue *other;
if (!(other = gst_structure_id_get_value (superset, field_id)))
* subtractions needs to give en empty set.
* Both substractions are switched below, as it's faster that way.
*/
- if (!gst_value_subtract (&subtraction, value, other)) {
- if (gst_value_subtract (&subtraction, other, value)) {
- g_value_unset (&subtraction);
+ if (!gst_value_subtract (NULL, value, other)) {
+ if (gst_value_subtract (NULL, other, value)) {
return TRUE;
}
- } else {
- g_value_unset (&subtraction);
}
return FALSE;
}
diff --git a/gst/gstvalue.c b/gst/gstvalue.c
index eed6e021406019c46ba47337cdbb472c53c66f53..19d7e5fd6d22a036fdb31f59edb3768b951372bf 100644 (file)
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
* range */
if (val < min || val > max) {
/* and the result is the int */
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
return FALSE;
}
+ if (!dest)
+ return TRUE;
+
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT_RANGE);
gst_value_set_int_range (pv1, min1, max1);
/* value is outside of the range, return range unchanged */
if (val < min || val > max) {
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT too as val <= max */
min++;
val++;
}
- gst_value_create_new_range (dest, min, val - 1, val + 1, max);
+ if (dest)
+ gst_value_create_new_range (dest, min, val - 1, val + 1, max);
}
return TRUE;
}
* range */
if (val < min || val > max) {
/* and the result is the int64 */
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
return FALSE;
}
+ if (!dest)
+ return TRUE;
+
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_INT64_RANGE);
gst_value_set_int64_range (pv1, min1, max1);
/* value is outside of the range, return range unchanged */
if (val < min || val > max) {
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
} else {
/* max must be MAXINT64 too as val <= max */
min++;
val++;
}
- gst_value_create_new_int64_range (dest, min, val - 1, val + 1, max);
+ if (dest)
+ gst_value_create_new_int64_range (dest, min, val - 1, val + 1, max);
}
return TRUE;
}
@@ -3089,7 +3101,8 @@ gst_value_subtract_double_double_range (GValue * dest, const GValue * minuend,
gdouble val = g_value_get_double (minuend);
if (val < min || val > max) {
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
@@ -3101,7 +3114,8 @@ gst_value_subtract_double_range_double (GValue * dest, const GValue * minuend,
{
/* since we don't have open ranges, we cannot create a hole in
* a double range. We return the original range */
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
}
+ if (!dest)
+ return TRUE;
+
if (min1 < max1) {
g_value_init (pv1, GST_TYPE_DOUBLE_RANGE);
gst_value_set_double_range (pv1, min1, max1);
for (i = 0; i < size; i++) {
const GValue *cur = VALUE_LIST_GET_VALUE (minuend, i);
+ /* quicker version when we can discard the result */
+ if (!dest) {
+ if (gst_value_subtract (NULL, cur, subtrahend)) {
+ ret = TRUE;
+ break;
+ }
+ continue;
+ }
+
if (gst_value_subtract (&subtraction, cur, subtrahend)) {
if (!ret) {
gst_value_init_and_copy (dest, &subtraction);
return FALSE;
}
}
- gst_value_init_and_copy (dest, result);
+ if (dest)
+ gst_value_init_and_copy (dest, result);
g_value_unset (result);
return TRUE;
}
gst_value_compare_with_func (minuend, max, compare) ==
GST_VALUE_GREATER_THAN) {
/* and the result is the value */
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
}
{
/* since we don't have open ranges, we cannot create a hole in
* a range. We return the original range */
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}
return FALSE;
}
+ if (!dest)
+ return TRUE;
+
if (cmp1 == GST_VALUE_LESS_THAN) {
g_value_init (pv1, GST_TYPE_FRACTION_RANGE);
gst_value_set_fraction_range (pv1, min1, max1);
/**
* gst_value_subtract:
* @dest: (out caller-allocates): the destination value for the result if the
- * subtraction is not empty
+ * subtraction is not empty. May be NULL, in which case the resulting set
+ * will not be computed, which can give a fair speedup.
* @minuend: the value to subtract from
* @subtrahend: the value to subtract
*
guint i, len;
GType ltype, mtype, stype;
- g_return_val_if_fail (dest != NULL, FALSE);
g_return_val_if_fail (G_IS_VALUE (minuend), FALSE);
g_return_val_if_fail (G_IS_VALUE (subtrahend), FALSE);
}
if (gst_value_compare (minuend, subtrahend) != GST_VALUE_EQUAL) {
- gst_value_init_and_copy (dest, minuend);
+ if (dest)
+ gst_value_init_and_copy (dest, minuend);
return TRUE;
}