mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2024-12-28 11:10:37 +00:00
gstcaps: Use direct values for repetitive conditionals (for/while).
This commit is contained in:
parent
d628988e0a
commit
5d819beffb
1 changed files with 30 additions and 25 deletions
|
@ -270,14 +270,15 @@ gst_caps_copy (const GstCaps * caps)
|
|||
{
|
||||
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));
|
||||
}
|
||||
|
@ -289,12 +290,12 @@ static void
|
|||
_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);
|
||||
|
@ -608,9 +609,7 @@ gst_caps_append (GstCaps * caps1, GstCaps * caps2)
|
|||
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);
|
||||
}
|
||||
|
@ -656,9 +655,7 @@ gst_caps_merge (GstCaps * caps1, GstCaps * caps2)
|
|||
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);
|
||||
}
|
||||
|
@ -1218,7 +1215,7 @@ GstCaps *
|
|||
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;
|
||||
|
@ -1260,16 +1257,18 @@ gst_caps_intersect (const GstCaps * caps1, const GstCaps * caps2)
|
|||
* 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);
|
||||
|
||||
|
@ -1360,7 +1359,7 @@ gst_caps_structure_subtract (GSList ** into, const GstStructure * minuend,
|
|||
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;
|
||||
|
@ -1380,17 +1379,20 @@ gst_caps_subtract (const GstCaps * minuend, const GstCaps * subtrahend)
|
|||
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;
|
||||
|
@ -1472,7 +1474,8 @@ gst_caps_normalize_foreach (GQuark field_id, const GValue * value, gpointer ptr)
|
|||
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);
|
||||
|
||||
|
@ -1504,14 +1507,15 @@ gst_caps_normalize (const GstCaps * caps)
|
|||
{
|
||||
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,
|
||||
|
@ -1798,7 +1802,7 @@ gst_caps_replace (GstCaps ** caps, GstCaps * newcaps)
|
|||
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,
|
||||
|
@ -1819,14 +1823,15 @@ gst_caps_to_string (const GstCaps * caps)
|
|||
|
||||
/* 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) {
|
||||
|
|
Loading…
Reference in a new issue