caps, structure, taglist: micro-optimisations
authorTim-Philipp Müller <tim@centricular.net>
Sat, 22 Dec 2012 16:50:49 +0000 (16:50 +0000)
committerTim-Philipp Müller <tim@centricular.net>
Sat, 22 Dec 2012 16:55:26 +0000 (16:55 +0000)
Avoid some unnecessary GValue copying by making use of
gst_structure_id_take_value() where possible.

gst/gstcaps.c
gst/gststructure.c
gst/gsttaglist.c

index 48b4f9a..b17c929 100644 (file)
@@ -1350,8 +1350,7 @@ gst_caps_structure_subtract_field (GQuark field_id, const GValue * value,
     return FALSE;
   } else {
     structure = gst_structure_copy (e->subtract_from);
-    gst_structure_id_set_value (structure, field_id, &subtraction);
-    g_value_unset (&subtraction);
+    gst_structure_id_take_value (structure, field_id, &subtraction);
     e->put_into = g_slist_prepend (e->put_into, structure);
     return TRUE;
   }
@@ -1488,9 +1487,7 @@ gst_caps_normalize_foreach (GQuark field_id, const GValue * value, gpointer ptr)
     }
 
     gst_value_init_and_copy (&val, gst_value_list_get_value (value, 0));
-    gst_structure_id_set_value (nf->structure, field_id, &val);
-    g_value_unset (&val);
-
+    gst_structure_id_take_value (nf->structure, field_id, &val);
     return FALSE;
   }
   return TRUE;
@@ -1611,11 +1608,12 @@ gst_caps_structure_simplify (GstStructure ** result,
      * but at most one field: field.name */
     if (G_IS_VALUE (&field.value)) {
       if (gst_structure_n_fields (simplify) == gst_structure_n_fields (compare)) {
-        gst_structure_id_set_value (compare, field.name, &field.value);
+        gst_structure_id_take_value (compare, field.name, &field.value);
         *result = NULL;
         ret = TRUE;
+      } else {
+        g_value_unset (&field.value);
       }
-      g_value_unset (&field.value);
     } else if (gst_structure_n_fields (simplify) <=
         gst_structure_n_fields (compare)) {
       /* compare is just more specific, will be optimized away later */
index 91919e6..919fc57 100644 (file)
@@ -2687,8 +2687,7 @@ default_fixate (GQuark field_id, const GValue * value, gpointer data)
   GValue v = { 0 };
 
   if (gst_value_fixate (&v, value)) {
-    gst_structure_id_set_value (s, field_id, &v);
-    g_value_unset (&v);
+    gst_structure_id_take_value (s, field_id, &v);
   }
   return TRUE;
 }
@@ -3023,8 +3022,7 @@ gst_structure_intersect_field1 (GQuark id, const GValue * val1, gpointer data)
   } else {
     GValue dest_value = { 0 };
     if (gst_value_intersect (&dest_value, val1, val2)) {
-      gst_structure_id_set_value (idata->dest, id, &dest_value);
-      g_value_unset (&dest_value);
+      gst_structure_id_take_value (idata->dest, id, &dest_value);
     } else {
       return FALSE;
     }
index 9bbe721..df6b588 100644 (file)
@@ -1026,13 +1026,11 @@ gst_tag_list_add_value_internal (GstTagList * tag_list, GstTagMergeMode mode,
         break;
       case GST_TAG_MERGE_PREPEND:
         gst_value_list_merge (&dest, value, value2);
-        gst_structure_id_set_value (list, tag_quark, &dest);
-        g_value_unset (&dest);
+        gst_structure_id_take_value (list, tag_quark, &dest);
         break;
       case GST_TAG_MERGE_APPEND:
         gst_value_list_merge (&dest, value2, value);
-        gst_structure_id_set_value (list, tag_quark, &dest);
-        g_value_unset (&dest);
+        gst_structure_id_take_value (list, tag_quark, &dest);
         break;
       case GST_TAG_MERGE_KEEP:
       case GST_TAG_MERGE_KEEP_ALL: