{
GstCaps *newcaps;
GstStructure *structure;
- guint i;
+ guint i, n;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
newcaps = gst_caps_new_empty ();
newcaps->flags = caps->flags;
+ n = caps->structs->len;
- for (i = 0; i < caps->structs->len; i++) {
+ for (i = 0; i < n; i++) {
structure = gst_caps_get_structure_unchecked (caps, i);
gst_caps_append_structure (newcaps, gst_structure_copy (structure));
}
_gst_caps_free (GstCaps * caps)
{
GstStructure *structure;
- guint i;
+ guint i, len;
/* The refcount must be 0, but since we're only called by gst_caps_unref,
* don't bother testing. */
-
- for (i = 0; i < caps->structs->len; i++) {
+ len = caps->structs->len;
+ for (i = 0; i < len; i++) {
structure = (GstStructure *) gst_caps_get_structure_unchecked (caps, i);
gst_structure_set_parent_refcount (structure, NULL);
gst_structure_free (structure);
gst_structure_free (structure);
}
} else {
- int len = caps2->structs->len;
-
- for (i = 0; i < len; i++) {
+ for (i = caps2->structs->len; i; i--) {
structure = gst_caps_remove_and_get_structure (caps2, 0);
gst_caps_append_structure (caps1, structure);
}
gst_structure_free (structure);
}
} else {
- int len = caps2->structs->len;
-
- for (i = 0; i < len; i++) {
+ for (i = caps2->structs->len; i; i--) {
structure = gst_caps_remove_and_get_structure (caps2, 0);
gst_caps_merge_structure (caps1, structure);
}
gst_caps_intersect (const GstCaps * caps1, const GstCaps * caps2)
{
guint64 i; /* index can be up to 2 * G_MAX_UINT */
- guint j, k;
+ guint j, k, len1, len2;
GstStructure *struct1;
GstStructure *struct2;
* the structures diagonally down, then we iterate over the caps2
* structures.
*/
- for (i = 0; i < caps1->structs->len + caps2->structs->len - 1; i++) {
+ len1 = caps1->structs->len;
+ len2 = caps2->structs->len;
+ for (i = 0; i < len1 + len2 - 1; i++) {
/* caps1 index goes from 0 to caps1->structs->len-1 */
- j = MIN (i, caps1->structs->len - 1);
+ j = MIN (i, len1 - 1);
/* caps2 index stays 0 until i reaches caps1->structs->len, then it counts
* up from 1 to caps2->structs->len - 1 */
k = MAX (0, i - j);
/* now run the diagonal line, end condition is the left or bottom
* border */
- while (k < caps2->structs->len) {
+ while (k < len2) {
struct1 = gst_caps_get_structure_unchecked (caps1, j);
struct2 = gst_caps_get_structure_unchecked (caps2, k);
GstCaps *
gst_caps_subtract (const GstCaps * minuend, const GstCaps * subtrahend)
{
- guint i, j;
+ guint i, j, sublen;
GstStructure *min;
GstStructure *sub;
GstCaps *dest = NULL, *src;
You can only remove everything or nothing and that is done above.
Note: there's a test that checks this behaviour. */
g_return_val_if_fail (!gst_caps_is_any (minuend), NULL);
- g_assert (subtrahend->structs->len > 0);
+ g_assert ((sublen = subtrahend->structs->len) > 0);
src = gst_caps_copy (minuend);
- for (i = 0; i < subtrahend->structs->len; i++) {
+ for (i = 0; i < sublen; i++) {
+ guint srclen;
+
sub = gst_caps_get_structure_unchecked (subtrahend, i);
if (dest) {
gst_caps_unref (src);
src = dest;
}
dest = gst_caps_new_empty ();
- for (j = 0; j < src->structs->len; j++) {
+ srclen = src->structs->len;
+ for (j = 0; j < srclen; j++) {
min = gst_caps_get_structure_unchecked (src, j);
if (gst_structure_get_name_id (min) == gst_structure_get_name_id (sub)) {
GSList *list;
guint i;
if (G_VALUE_TYPE (value) == GST_TYPE_LIST) {
- for (i = 1; i < gst_value_list_get_size (value); i++) {
+ guint len = gst_value_list_get_size (value);
+ for (i = 1; i < len; i++) {
const GValue *v = gst_value_list_get_value (value, i);
GstStructure *structure = gst_structure_copy (nf->structure);
{
NormalizeForeach nf;
GstCaps *newcaps;
- guint i;
+ guint i, nlen;
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
newcaps = gst_caps_copy (caps);
nf.caps = newcaps;
+ nlen = newcaps->structs->len;
- for (i = 0; i < newcaps->structs->len; i++) {
+ for (i = 0; i < nlen; i++) {
nf.structure = gst_caps_get_structure_unchecked (newcaps, i);
while (!gst_structure_foreach (nf.structure,
gchar *
gst_caps_to_string (const GstCaps * caps)
{
- guint i, slen;
+ guint i, slen, clen;
GString *s;
/* NOTE: This function is potentially called by the debug system,
/* estimate a rough string length to avoid unnecessary reallocs in GString */
slen = 0;
- for (i = 0; i < caps->structs->len; i++) {
+ clen = caps->structs->len;
+ for (i = 0; i < clen; i++) {
slen +=
STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure_unchecked (caps,
i));
}
s = g_string_sized_new (slen);
- for (i = 0; i < caps->structs->len; i++) {
+ for (i = 0; i < clen; i++) {
GstStructure *structure;
if (i > 0) {