diff options
-rw-r--r-- | gst/gstpad.c | 20 | ||||
-rw-r--r-- | gst/gstregistrybinary.c | 11 | ||||
-rw-r--r-- | gst/gstvalue.c | 78 |
3 files changed, 64 insertions, 45 deletions
diff --git a/gst/gstpad.c b/gst/gstpad.c index 9dc09ef63e..20069f6957 100644 --- a/gst/gstpad.c +++ b/gst/gstpad.c @@ -143,15 +143,13 @@ static GstFlowQuarks flow_quarks[] = { {GST_FLOW_NOT_LINKED, "not-linked", 0}, {GST_FLOW_WRONG_STATE, "wrong-state", 0}, {GST_FLOW_UNEXPECTED, "unexpected", 0}, {GST_FLOW_NOT_NEGOTIATED, "not-negotiated", 0}, {GST_FLOW_ERROR, "error", 0}, {GST_FLOW_NOT_SUPPORTED, "not-supported", 0}, - {GST_FLOW_CUSTOM_ERROR, "custom-error", 0}, - - {0, NULL, 0} + {GST_FLOW_CUSTOM_ERROR, "custom-error", 0} }; /** * gst_flow_get_name: * @ret: a #GstFlowReturn to get the name of. * @@ -163,13 +161,13 @@ G_CONST_RETURN gchar * gst_flow_get_name (GstFlowReturn ret) { gint i; ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS); - for (i = 0; flow_quarks[i].name; i++) { + for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { if (ret == flow_quarks[i].ret) return flow_quarks[i].name; } return "unknown"; } @@ -186,13 +184,13 @@ GQuark gst_flow_to_quark (GstFlowReturn ret) { gint i; ret = CLAMP (ret, GST_FLOW_CUSTOM_ERROR, GST_FLOW_CUSTOM_SUCCESS); - for (i = 0; flow_quarks[i].name; i++) { + for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { if (ret == flow_quarks[i].ret) return flow_quarks[i].quark; } return 0; } @@ -200,13 +198,13 @@ gst_flow_to_quark (GstFlowReturn ret) { \ gint i; \ \ buffer_quark = g_quark_from_static_string ("buffer"); \ event_quark = g_quark_from_static_string ("event"); \ \ - for (i = 0; flow_quarks[i].name; i++) { \ + for (i = 0; i < G_N_ELEMENTS (flow_quarks); i++) { \ flow_quarks[i].quark = g_quark_from_static_string (flow_quarks[i].name); \ } \ \ GST_DEBUG_CATEGORY_INIT (debug_dataflow, "GST_DATAFLOW", \ GST_DEBUG_BOLD | GST_DEBUG_FG_GREEN, "dataflow inside pads"); \ } @@ -2290,16 +2288,17 @@ fixate_value (GValue * dest, const GValue * src) if (!fixate_value (dest, &temp)) gst_value_init_and_copy (dest, &temp); g_value_unset (&temp); } else if (G_VALUE_TYPE (src) == GST_TYPE_ARRAY) { gboolean res = FALSE; - guint n; + guint n, len; + len = gst_value_array_get_size (src); g_value_init (dest, GST_TYPE_ARRAY); - for (n = 0; n < gst_value_array_get_size (src); n++) { + for (n = 0; n < len; n++) { GValue kid = { 0 }; const GValue *orig_kid = gst_value_array_get_value (src, n); if (!fixate_value (&kid, orig_kid)) gst_value_init_and_copy (&kid, orig_kid); else @@ -2342,13 +2341,13 @@ gst_pad_default_fixate (GQuark field_id, const GValue * value, gpointer data) * make sure that the caps are actually writable (see gst_caps_make_writable()). */ void gst_pad_fixate_caps (GstPad * pad, GstCaps * caps) { GstPadFixateCapsFunction fixatefunc; - guint n; + guint n, len; g_return_if_fail (GST_IS_PAD (pad)); g_return_if_fail (caps != NULL); if (gst_caps_is_fixed (caps)) return; @@ -2356,13 +2355,14 @@ gst_pad_fixate_caps (GstPad * pad, GstCaps * caps) fixatefunc = GST_PAD_FIXATECAPSFUNC (pad); if (fixatefunc) { fixatefunc (pad, caps); } /* default fixation */ - for (n = 0; n < gst_caps_get_size (caps); n++) { + len = gst_caps_get_size (caps); + for (n = 0; n < len; n++) { GstStructure *s = gst_caps_get_structure (caps, n); gst_structure_foreach (s, gst_pad_default_fixate, s); } } diff --git a/gst/gstregistrybinary.c b/gst/gstregistrybinary.c index 654354a91b..c24e191c0e 100644 --- a/gst/gstregistrybinary.c +++ b/gst/gstregistrybinary.c @@ -1117,13 +1117,13 @@ static gboolean gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in, gchar * end) { GstBinaryPluginElement *pe; GstPlugin *plugin = NULL; gchar *cache_str = NULL; - guint i; + guint i, n; align (*in); GST_LOG ("Reading/casting for GstBinaryPluginElement at address %p", *in); unpack_element (*in, pe, GstBinaryPluginElement, end, fail); plugin = g_object_new (GST_TYPE_PLUGIN, NULL); @@ -1159,19 +1159,20 @@ gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in, g_free (cache_str); plugin->basename = g_path_get_basename (plugin->filename); /* Takes ownership of plugin */ gst_registry_add_plugin (registry, plugin); + n = pe->nfeatures; GST_DEBUG ("Added plugin '%s' plugin with %d features from binary registry", - plugin->desc.name, pe->nfeatures); + plugin->desc.name, n); /* Load plugin features */ - for (i = 0; i < pe->nfeatures; i++) { - if (!gst_registry_binary_load_feature (registry, in, end, - plugin->desc.name)) { + for (i = 0; i < n; i++) { + if (G_UNLIKELY (!gst_registry_binary_load_feature (registry, in, end, + plugin->desc.name))) { GST_ERROR ("Error while loading binary feature"); gst_registry_remove_plugin (registry, plugin); goto fail; } } diff --git a/gst/gstvalue.c b/gst/gstvalue.c index ef647cef9f..bbcfa1d4ac 100644 --- a/gst/gstvalue.c +++ b/gst/gstvalue.c @@ -122,22 +122,23 @@ gst_value_serialize_any_list (const GValue * value, const gchar * begin, { guint i; GArray *array = value->data[0].v_pointer; GString *s; GValue *v; gchar *s_val; + guint alen = array->len; /* estimate minimum string length to minimise re-allocs in GString */ - s = g_string_sized_new (2 + (6 * array->len) + 2); + s = g_string_sized_new (2 + (6 * alen) + 2); g_string_append (s, begin); - for (i = 0; i < array->len; i++) { + for (i = 0; i < alen; i++) { v = &g_array_index (array, GValue, i); s_val = gst_value_serialize (v); g_string_append (s, s_val); g_free (s_val); - if (i < array->len - 1) { + if (i < alen - 1) { g_string_append_len (s, ", ", 2); } } g_string_append (s, end); return g_string_free (s, FALSE); } @@ -148,19 +149,21 @@ gst_value_transform_any_list_string (const GValue * src_value, { GValue *list_value; GArray *array; GString *s; guint i; gchar *list_s; + guint alen; array = src_value->data[0].v_pointer; + alen = array->len; /* estimate minimum string length to minimise re-allocs in GString */ - s = g_string_sized_new (2 + (10 * array->len) + 2); + s = g_string_sized_new (2 + (10 * alen) + 2); g_string_append (s, begin); - for (i = 0; i < array->len; i++) { + for (i = 0; i < alen; i++) { list_value = &g_array_index (array, GValue, i); if (i != 0) { g_string_append_len (s, ", ", 2); } list_s = g_strdup_value_contents (list_value); @@ -210,17 +213,18 @@ gst_value_init_list_or_array (GValue * value) } static GArray * copy_garray_of_gstvalue (const GArray * src) { GArray *dest; - guint i; + guint i, len; - dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), src->len); - g_array_set_size (dest, src->len); - for (i = 0; i < src->len; i++) { + len = src->len; + dest = g_array_sized_new (FALSE, TRUE, sizeof (GValue), len); + g_array_set_size (dest, len); + for (i = 0; i < len; i++) { gst_value_init_and_copy (&g_array_index (dest, GValue, i), &g_array_index (src, GValue, i)); } return dest; } @@ -232,17 +236,18 @@ gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value) copy_garray_of_gstvalue ((GArray *) src_value->data[0].v_pointer); } static void gst_value_free_list_or_array (GValue * value) { - guint i; + guint i, len; GArray *src = (GArray *) value->data[0].v_pointer; + len = src->len; if ((value->data[1].v_uint & G_VALUE_NOCOPY_CONTENTS) == 0) { - for (i = 0; i < src->len; i++) { + for (i = 0; i < len; i++) { g_value_unset (&g_array_index (src, GValue, i)); } g_array_free (src, TRUE); } } @@ -551,19 +556,20 @@ gst_value_compare_list (const GValue * value1, const GValue * value2) static int gst_value_compare_array (const GValue * value1, const GValue * value2) { guint i; GArray *array1 = value1->data[0].v_pointer; GArray *array2 = value2->data[0].v_pointer; + guint len = array1->len; GValue *v1; GValue *v2; - if (array1->len != array2->len) + if (len != array2->len) return GST_VALUE_UNORDERED; - for (i = 0; i < array1->len; i++) { + for (i = 0; i < len; i++) { v1 = &g_array_index (array1, GValue, i); v2 = &g_array_index (array2, GValue, i); if (gst_value_compare (v1, v2) != GST_VALUE_EQUAL) return GST_VALUE_UNORDERED; } @@ -2836,14 +2842,16 @@ gst_value_get_compare_func (const GValue * value1) /* this is a fast check */ best = gst_value_hash_lookup_type (type1); /* slower checks */ if (G_UNLIKELY (!best || !best->compare)) { + guint len = gst_value_table->len; + best = NULL; - for (i = 0; i < gst_value_table->len; i++) { + for (i = 0; i < len; i++) { table = &g_array_index (gst_value_table, GstValueTable, i); if (table->compare && g_type_is_a (type1, table->type)) { if (!best || g_type_is_a (table->type, best->type)) best = table; } } @@ -2946,15 +2954,17 @@ gst_value_compare_with_func (const GValue * value1, const GValue * value2, * be unioned. */ gboolean gst_value_can_union (const GValue * value1, const GValue * value2) { GstValueUnionInfo *union_info; - guint i; + guint i, len; + + len = gst_value_union_funcs->len; - for (i = 0; i < gst_value_union_funcs->len; i++) { + for (i = 0; i < len; i++) { union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i); if (union_info->type1 == G_VALUE_TYPE (value1) && union_info->type2 == G_VALUE_TYPE (value2)) return TRUE; if (union_info->type1 == G_VALUE_TYPE (value2) && union_info->type2 == G_VALUE_TYPE (value1)) @@ -2976,15 +2986,17 @@ gst_value_can_union (const GValue * value1, const GValue * value2) */ /* FIXME: change return type to 'void'? */ gboolean gst_value_union (GValue * dest, const GValue * value1, const GValue * value2) { GstValueUnionInfo *union_info; - guint i; + guint i, len; + + len = gst_value_union_funcs->len; - for (i = 0; i < gst_value_union_funcs->len; i++) { + for (i = 0; i < len; i++) { union_info = &g_array_index (gst_value_union_funcs, GstValueUnionInfo, i); if (union_info->type1 == G_VALUE_TYPE (value1) && union_info->type2 == G_VALUE_TYPE (value2)) { if (union_info->func (dest, value1, value2)) { return TRUE; } @@ -3041,25 +3053,26 @@ gst_value_register_union_func (GType type1, GType type2, GstValueUnionFunc func) * Returns: TRUE if the values can intersect */ gboolean gst_value_can_intersect (const GValue * value1, const GValue * value2) { GstValueIntersectInfo *intersect_info; - guint i; + guint i, len; GType ltype, type1, type2; ltype = gst_value_list_get_type (); /* special cases */ if (G_VALUE_HOLDS (value1, ltype) || G_VALUE_HOLDS (value2, ltype)) return TRUE; type1 = G_VALUE_TYPE (value1); type2 = G_VALUE_TYPE (value2); - for (i = 0; i < gst_value_intersect_funcs->len; i++) { + 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 == intersect_info->type2 && intersect_info->type1 == type1 && intersect_info->type2 == type2) return TRUE; } @@ -3083,13 +3096,13 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2) */ gboolean gst_value_intersect (GValue * dest, const GValue * value1, const GValue * value2) { GstValueIntersectInfo *intersect_info; - guint i; + guint i, len; GType ltype, type1, type2; ltype = gst_value_list_get_type (); /* special cases first */ if (G_VALUE_HOLDS (value1, ltype)) @@ -3102,13 +3115,14 @@ gst_value_intersect (GValue * dest, const GValue * value1, return TRUE; } type1 = G_VALUE_TYPE (value1); type2 = G_VALUE_TYPE (value2); - for (i = 0; i < gst_value_intersect_funcs->len; i++) { + 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) { @@ -3161,13 +3175,13 @@ gst_value_register_intersect_func (GType type1, GType type2, */ gboolean gst_value_subtract (GValue * dest, const GValue * minuend, const GValue * subtrahend) { GstValueSubtractInfo *info; - guint i; + guint i, len; GType ltype, mtype, stype; ltype = gst_value_list_get_type (); /* special cases first */ if (G_VALUE_HOLDS (minuend, ltype)) @@ -3175,13 +3189,14 @@ gst_value_subtract (GValue * dest, const GValue * minuend, if (G_VALUE_HOLDS (subtrahend, ltype)) return gst_value_subtract_list (dest, minuend, subtrahend); mtype = G_VALUE_TYPE (minuend); stype = G_VALUE_TYPE (subtrahend); - for (i = 0; i < gst_value_subtract_funcs->len; i++) { + len = gst_value_subtract_funcs->len; + for (i = 0; i < len; i++) { info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i); if (info->minuend == mtype && info->subtrahend == stype) { return info->func (dest, minuend, subtrahend); } } @@ -3217,25 +3232,26 @@ gst_value_subtract (GValue * dest, const GValue * minuend, * Returns: TRUE if a subtraction is possible */ gboolean gst_value_can_subtract (const GValue * minuend, const GValue * subtrahend) { GstValueSubtractInfo *info; - guint i; + guint i, len; GType ltype, mtype, stype; ltype = gst_value_list_get_type (); /* special cases */ if (G_VALUE_HOLDS (minuend, ltype) || G_VALUE_HOLDS (subtrahend, ltype)) return TRUE; mtype = G_VALUE_TYPE (minuend); stype = G_VALUE_TYPE (subtrahend); - for (i = 0; i < gst_value_subtract_funcs->len; i++) { + len = gst_value_subtract_funcs->len; + for (i = 0; i < len; i++) { info = &g_array_index (gst_value_subtract_funcs, GstValueSubtractInfo, i); if (info->minuend == mtype && info->subtrahend == stype) return TRUE; } return gst_value_can_compare (minuend, subtrahend); @@ -3318,27 +3334,28 @@ gst_value_init_and_copy (GValue * dest, const GValue * src) * * Returns: the serialization for @value or NULL if none exists */ gchar * gst_value_serialize (const GValue * value) { - guint i; + guint i, len; GValue s_val = { 0 }; GstValueTable *table, *best; char *s; GType type; g_return_val_if_fail (G_IS_VALUE (value), NULL); type = G_VALUE_TYPE (value); best = gst_value_hash_lookup_type (type); if (G_UNLIKELY (!best || !best->serialize)) { + len = gst_value_table->len; best = NULL; - for (i = 0; i < gst_value_table->len; i++) { + for (i = 0; i < len; i++) { table = &g_array_index (gst_value_table, GstValueTable, i); if (table->serialize && g_type_is_a (type, table->type)) { if (!best || g_type_is_a (table->type, best->type)) best = table; } } @@ -3368,24 +3385,25 @@ gst_value_serialize (const GValue * value) * Returns: TRUE on success */ gboolean gst_value_deserialize (GValue * dest, const gchar * src) { GstValueTable *table, *best; - guint i; + guint i, len; GType type; g_return_val_if_fail (src != NULL, FALSE); g_return_val_if_fail (G_IS_VALUE (dest), FALSE); type = G_VALUE_TYPE (dest); best = gst_value_hash_lookup_type (type); if (G_UNLIKELY (!best || !best->deserialize)) { + len = gst_value_table->len; best = NULL; - for (i = 0; i < gst_value_table->len; i++) { + for (i = 0; i < len; i++) { table = &g_array_index (gst_value_table, GstValueTable, i); if (table->deserialize && g_type_is_a (type, table->type)) { if (!best || g_type_is_a (table->type, best->type)) best = table; } } |