summaryrefslogtreecommitdiff
authorEdward Hervey <bilboed@bilboed.com>2009-06-29 09:20:12 (GMT)
committer Edward Hervey <bilboed@bilboed.com>2009-06-30 14:29:50 (GMT)
commit923913984e3b6448c9b9bae6d17a52a6f7a33646 (patch) (side-by-side diff)
tree263f6ddd1a603bc71897e3760c24183daa40a1f5
parent53b09c392ad1cb2325b2df498dcf6e7668ed22b6 (diff)
downloadgstreamer-923913984e3b6448c9b9bae6d17a52a6f7a33646.zip
gstreamer-923913984e3b6448c9b9bae6d17a52a6f7a33646.tar.gz
Use local variables in for/while loops.
This makes the generated code faster since: * It won't have to read an undirect value (which will most likely be outside of the L1/L2 cache) * We know that value never changes (the compiler has no clue that it doesn't).
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--gst/gstpad.c20
-rw-r--r--gst/gstregistrybinary.c11
-rw-r--r--gst/gstvalue.c78
3 files changed, 64 insertions, 45 deletions
diff --git a/gst/gstpad.c b/gst/gstpad.c
index 9dc09ef..20069f6 100644
--- a/gst/gstpad.c
+++ b/gst/gstpad.c
@@ -146,9 +146,7 @@ static GstFlowQuarks flow_quarks[] = {
{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}
};
/**
@@ -166,7 +164,7 @@ gst_flow_get_name (GstFlowReturn ret)
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;
}
@@ -189,7 +187,7 @@ gst_flow_to_quark (GstFlowReturn ret)
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;
}
@@ -203,7 +201,7 @@ gst_flow_to_quark (GstFlowReturn ret)
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); \
} \
\
@@ -2293,10 +2291,11 @@ fixate_value (GValue * dest, const GValue * src)
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);
@@ -2345,7 +2344,7 @@ 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);
@@ -2359,7 +2358,8 @@ gst_pad_fixate_caps (GstPad * pad, GstCaps * 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 654354a..c24e191 100644
--- a/gst/gstregistrybinary.c
+++ b/gst/gstregistrybinary.c
@@ -1120,7 +1120,7 @@ gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in,
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);
@@ -1162,13 +1162,14 @@ gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in,
/* 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 ef647ce..bbcfa1d 100644
--- a/gst/gstvalue.c
+++ b/gst/gstvalue.c
@@ -125,16 +125,17 @@ gst_value_serialize_any_list (const GValue * value, const gchar * begin,
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);
}
}
@@ -151,13 +152,15 @@ gst_value_transform_any_list_string (const GValue * src_value,
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) {
@@ -213,11 +216,12 @@ 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));
}
@@ -235,11 +239,12 @@ gst_value_copy_list_or_array (const GValue * src_value, GValue * dest_value)
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);
@@ -554,13 +559,14 @@ 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)
@@ -2839,8 +2845,10 @@ gst_value_get_compare_func (const GValue * value1)
/* 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))
@@ -2949,9 +2957,11 @@ 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))
@@ -2979,9 +2989,11 @@ 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)) {
@@ -3044,7 +3056,7 @@ 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 ();
@@ -3056,7 +3068,8 @@ gst_value_can_intersect (const GValue * value1, const GValue * value2)
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 &&
@@ -3086,7 +3099,7 @@ 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 ();
@@ -3105,7 +3118,8 @@ gst_value_intersect (GValue * dest, const GValue * value1,
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) {
@@ -3164,7 +3178,7 @@ 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 ();
@@ -3178,7 +3192,8 @@ gst_value_subtract (GValue * dest, const GValue * minuend,
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);
@@ -3220,7 +3235,7 @@ 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 ();
@@ -3232,7 +3247,8 @@ gst_value_can_subtract (const GValue * minuend, const GValue * 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 TRUE;
@@ -3321,7 +3337,7 @@ gst_value_init_and_copy (GValue * dest, const GValue * src)
gchar *
gst_value_serialize (const GValue * value)
{
- guint i;
+ guint i, len;
GValue s_val = { 0 };
GstValueTable *table, *best;
char *s;
@@ -3334,8 +3350,9 @@ gst_value_serialize (const GValue * 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))
@@ -3371,7 +3388,7 @@ 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);
@@ -3381,8 +3398,9 @@ gst_value_deserialize (GValue * dest, const gchar * src)
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))