summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Hervey <bilboed@bilboed.com>2009-06-29 11:23:31 +0200
committerEdward Hervey <bilboed@bilboed.com>2009-06-30 16:29:58 +0200
commit3c21f2d86c72fa2d8c8d6b8d5087599497c2673c (patch)
tree8afb91c8faa9d7cfd09576cfc9d05328e2ff4643
parent923913984e3b6448c9b9bae6d17a52a6f7a33646 (diff)
Spread branch prediction macros.
These are based on profiling several playback scenarios using playbin2.
-rw-r--r--gst/gstcaps.c38
-rw-r--r--gst/gstpad.c2
-rw-r--r--gst/gstregistry.c5
-rw-r--r--gst/gstregistrybinary.c27
-rw-r--r--gst/gststructure.c37
5 files changed, 56 insertions, 53 deletions
diff --git a/gst/gstcaps.c b/gst/gstcaps.c
index ba33ed9fa..958c7c588 100644
--- a/gst/gstcaps.c
+++ b/gst/gstcaps.c
@@ -509,7 +509,7 @@ gst_structure_is_equal_foreach (GQuark field_id, const GValue * val2,
GstStructure *struct1 = (GstStructure *) data;
const GValue *val1 = gst_structure_id_get_value (struct1, field_id);
- if (val1 == NULL)
+ if (G_UNLIKELY (val1 == NULL))
return FALSE;
if (gst_value_compare (val1, val2) == GST_VALUE_EQUAL) {
return TRUE;
@@ -601,7 +601,7 @@ gst_caps_append (GstCaps * caps1, GstCaps * caps2)
#ifdef USE_POISONING
CAPS_POISON (caps2);
#endif
- if (gst_caps_is_any (caps1) || gst_caps_is_any (caps2)) {
+ if (G_UNLIKELY (gst_caps_is_any (caps1) || gst_caps_is_any (caps2))) {
/* FIXME: this leaks */
caps1->flags |= GST_CAPS_FLAGS_ANY;
for (i = caps2->structs->len - 1; i >= 0; i--) {
@@ -643,12 +643,12 @@ gst_caps_merge (GstCaps * caps1, GstCaps * caps2)
#ifdef USE_POISONING
CAPS_POISON (caps2);
#endif
- if (gst_caps_is_any (caps1)) {
+ if (G_UNLIKELY (gst_caps_is_any (caps1))) {
for (i = caps2->structs->len - 1; i >= 0; i--) {
structure = gst_caps_remove_and_get_structure (caps2, i);
gst_structure_free (structure);
}
- } else if (gst_caps_is_any (caps2)) {
+ } else if (G_UNLIKELY (gst_caps_is_any (caps2))) {
caps1->flags |= GST_CAPS_FLAGS_ANY;
for (i = caps1->structs->len - 1; i >= 0; i--) {
structure = gst_caps_remove_and_get_structure (caps1, i);
@@ -831,7 +831,7 @@ gst_caps_copy_nth (const GstCaps * caps, guint nth)
newcaps = gst_caps_new_empty ();
newcaps->flags = caps->flags;
- if (caps->structs->len > nth) {
+ if (G_LIKELY (caps->structs->len > nth)) {
structure = gst_caps_get_structure_unchecked (caps, nth);
gst_caps_append_structure (newcaps, gst_structure_copy (structure));
}
@@ -1083,15 +1083,15 @@ gst_caps_is_equal (const GstCaps * caps1, const GstCaps * caps2)
* So there should be an assertion that caps1 and caps2 != NULL */
/* NULL <-> NULL is allowed here */
- if (caps1 == caps2)
+ if (G_UNLIKELY (caps1 == caps2))
return TRUE;
/* one of them NULL => they are different (can't be both NULL because
* we checked that above) */
- if (caps1 == NULL || caps2 == NULL)
+ if (G_UNLIKELY (caps1 == NULL || caps2 == NULL))
return FALSE;
- if (gst_caps_is_fixed (caps1) && gst_caps_is_fixed (caps2))
+ if (G_UNLIKELY (gst_caps_is_fixed (caps1) && gst_caps_is_fixed (caps2)))
return gst_caps_is_equal_fixed (caps1, caps2);
return gst_caps_is_subset (caps1, caps2) && gst_caps_is_subset (caps2, caps1);
@@ -1113,7 +1113,7 @@ gst_caps_structure_intersect_field (GQuark id, const GValue * val1,
GValue dest_value = { 0 };
const GValue *val2 = gst_structure_id_get_value (idata->intersect, id);
- if (val2 == NULL) {
+ if (G_UNLIKELY (val2 == NULL)) {
gst_structure_id_set_value (idata->dest, id, val1);
} else if (idata->first_run) {
if (gst_value_intersect (&dest_value, val1, val2)) {
@@ -1136,20 +1136,20 @@ gst_caps_structure_intersect (const GstStructure * struct1,
g_return_val_if_fail (struct1 != NULL, NULL);
g_return_val_if_fail (struct2 != NULL, NULL);
- if (struct1->name != struct2->name)
+ if (G_UNLIKELY (struct1->name != struct2->name))
return NULL;
data.dest = gst_structure_id_empty_new (struct1->name);
data.intersect = struct2;
data.first_run = TRUE;
- if (!gst_structure_foreach ((GstStructure *) struct1,
- gst_caps_structure_intersect_field, &data))
+ if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct1,
+ gst_caps_structure_intersect_field, &data)))
goto error;
data.intersect = struct1;
data.first_run = FALSE;
- if (!gst_structure_foreach ((GstStructure *) struct2,
- gst_caps_structure_intersect_field, &data))
+ if (G_UNLIKELY (!gst_structure_foreach ((GstStructure *) struct2,
+ gst_caps_structure_intersect_field, &data)))
goto error;
return data.dest;
@@ -1226,17 +1226,17 @@ gst_caps_intersect (const GstCaps * caps1, const GstCaps * caps2)
g_return_val_if_fail (GST_IS_CAPS (caps2), NULL);
/* caps are exactly the same pointers, just copy one caps */
- if (caps1 == caps2)
+ if (G_UNLIKELY (caps1 == caps2))
return gst_caps_copy (caps1);
/* empty caps on either side, return empty */
- if (gst_caps_is_empty (caps1) || gst_caps_is_empty (caps2))
+ if (G_UNLIKELY (gst_caps_is_empty (caps1) || gst_caps_is_empty (caps2)))
return gst_caps_new_empty ();
/* one of the caps is any, just copy the other caps */
- if (gst_caps_is_any (caps1))
+ if (G_UNLIKELY (gst_caps_is_any (caps1)))
return gst_caps_copy (caps2);
- if (gst_caps_is_any (caps2))
+ if (G_UNLIKELY (gst_caps_is_any (caps2)))
return gst_caps_copy (caps1);
dest = gst_caps_new_empty ();
@@ -1277,7 +1277,7 @@ gst_caps_intersect (const GstCaps * caps1, const GstCaps * caps2)
gst_caps_append_structure (dest, istruct);
/* move down left */
k++;
- if (j == 0)
+ if (G_UNLIKELY (j == 0))
break; /* so we don't roll back to G_MAXUINT */
j--;
}
diff --git a/gst/gstpad.c b/gst/gstpad.c
index 20069f695..cbcd25cbf 100644
--- a/gst/gstpad.c
+++ b/gst/gstpad.c
@@ -1766,7 +1766,7 @@ gst_pad_link_check_compatible_unlocked (GstPad * src, GstPad * sink)
/* if we have caps on both pads we can check the intersection. If one
* of the caps is NULL, we return TRUE. */
- if (srccaps == NULL || sinkcaps == NULL) {
+ if (G_UNLIKELY (srccaps == NULL || sinkcaps == NULL)) {
if (srccaps)
gst_caps_unref (srccaps);
if (sinkcaps)
diff --git a/gst/gstregistry.c b/gst/gstregistry.c
index 67e97fecf..88062d250 100644
--- a/gst/gstregistry.c
+++ b/gst/gstregistry.c
@@ -380,7 +380,7 @@ gst_registry_remove_features_for_plugin_unlocked (GstRegistry * registry,
GList *next = g_list_next (f);
GstPluginFeature *feature = f->data;
- if (feature && !strcmp (feature->plugin_name, name)) {
+ if (G_UNLIKELY (feature && !strcmp (feature->plugin_name, name))) {
GST_DEBUG_OBJECT (registry, "removing feature %p (%s) for plugin %s",
feature, gst_plugin_feature_get_name (feature), name);
@@ -755,7 +755,8 @@ gst_registry_lookup_locked (GstRegistry * registry, const char *filename)
/* FIXME: use GTree speed up lookups */
for (g = registry->plugins; g; g = g_list_next (g)) {
plugin = GST_PLUGIN_CAST (g->data);
- if (plugin->basename && strcmp (basename, plugin->basename) == 0) {
+ if (G_UNLIKELY (plugin->basename
+ && strcmp (basename, plugin->basename) == 0)) {
g_free (basename);
return plugin;
}
diff --git a/gst/gstregistrybinary.c b/gst/gstregistrybinary.c
index c24e191c0..222e74987 100644
--- a/gst/gstregistrybinary.c
+++ b/gst/gstregistrybinary.c
@@ -76,12 +76,12 @@ _strnlen (const gchar * str, gint maxlen)
{
gint len = 0;
- if (len == maxlen)
+ if (G_UNLIKELY (len == maxlen))
return -1;
while (*str++ != '\0') {
len++;
- if (len == maxlen)
+ if (G_UNLIKELY (len == maxlen))
return -1;
}
return len;
@@ -913,26 +913,26 @@ gst_registry_binary_load_feature (GstRegistry * registry, gchar ** in,
/* unpack plugin feature strings */
unpack_string (*in, type_name, end, fail);
- if (!type_name) {
+ if (G_UNLIKELY (!type_name)) {
GST_ERROR ("No feature type name");
return FALSE;
}
GST_DEBUG ("Plugin '%s' feature typename : '%s'", plugin_name, type_name);
- if (!(type = g_type_from_name (type_name))) {
+ if (G_UNLIKELY (!(type = g_type_from_name (type_name)))) {
GST_ERROR ("Unknown type from typename '%s' for plugin '%s'", type_name,
plugin_name);
g_free (type_name);
return FALSE;
}
- if ((feature = g_object_new (type, NULL)) == NULL) {
+ if (G_UNLIKELY ((feature = g_object_new (type, NULL)) == NULL)) {
GST_ERROR ("Can't create feature from type");
g_free (type_name);
return FALSE;
}
- if (!GST_IS_PLUGIN_FEATURE (feature)) {
+ if (G_UNLIKELY (!GST_IS_PLUGIN_FEATURE (feature))) {
GST_ERROR ("typename : '%s' is not a plugin feature", type_name);
goto fail;
}
@@ -1178,7 +1178,7 @@ gst_registry_binary_load_plugin (GstRegistry * registry, gchar ** in,
/* Load external plugin dependencies */
for (i = 0; i < pe->n_deps; ++i) {
- if (!gst_registry_binary_load_plugin_dep (plugin, in, end)) {
+ if (G_UNLIKELY (!gst_registry_binary_load_plugin_dep (plugin, in, end))) {
GST_ERROR_OBJECT (plugin, "Could not read external plugin dependency");
gst_registry_remove_plugin (registry, plugin);
goto fail;
@@ -1228,7 +1228,7 @@ gst_registry_binary_read_cache (GstRegistry * registry, const char *location)
#endif
mapped = g_mapped_file_new (location, FALSE, &err);
- if (err != NULL) {
+ if (G_UNLIKELY (err != NULL)) {
GST_INFO ("Unable to mmap file %s : %s", location, err->message);
g_error_free (err);
err = NULL;
@@ -1243,7 +1243,7 @@ gst_registry_binary_read_cache (GstRegistry * registry, const char *location)
return FALSE;
}
} else {
- if ((contents = g_mapped_file_get_contents (mapped)) == NULL) {
+ if (G_UNLIKELY ((contents = g_mapped_file_get_contents (mapped)) == NULL)) {
GST_ERROR ("Can't load file %s : %s", location, g_strerror (errno));
goto Error;
}
@@ -1254,13 +1254,14 @@ gst_registry_binary_read_cache (GstRegistry * registry, const char *location)
/* in is a cursor pointer, we initialize it with the begin of registry and is updated on each read */
in = contents;
GST_DEBUG ("File data at address %p", in);
- if (size < sizeof (GstBinaryRegistryMagic)) {
+ if (G_UNLIKELY (size < sizeof (GstBinaryRegistryMagic))) {
GST_ERROR ("No or broken registry header");
goto Error;
}
/* check if header is valid */
- if ((check_magic_result = gst_registry_binary_check_magic (&in, size)) < 0) {
+ if (G_UNLIKELY ((check_magic_result =
+ gst_registry_binary_check_magic (&in, size)) < 0)) {
if (check_magic_result == -1)
GST_ERROR
@@ -1270,8 +1271,8 @@ gst_registry_binary_read_cache (GstRegistry * registry, const char *location)
}
/* check if there are plugins in the file */
- if (!(((gsize) in + sizeof (GstBinaryPluginElement)) <
- (gsize) contents + size)) {
+ if (G_UNLIKELY (!(((gsize) in + sizeof (GstBinaryPluginElement)) <
+ (gsize) contents + size))) {
GST_INFO ("No binary plugins structure to read");
/* empty file, this is not an error */
} else {
diff --git a/gst/gststructure.c b/gst/gststructure.c
index 2c8fa95b3..2d512b6ea 100644
--- a/gst/gststructure.c
+++ b/gst/gststructure.c
@@ -155,7 +155,7 @@ gst_structure_validate_name (const gchar * name)
g_return_val_if_fail (name != NULL, FALSE);
/* FIXME 0.11: use g_ascii_isalpha() */
- if (!g_ascii_isalnum (*name)) {
+ if (G_UNLIKELY (!g_ascii_isalnum (*name))) {
GST_WARNING ("Invalid character '%c' at offset 0 in structure name: %s",
*name, name);
return FALSE;
@@ -166,7 +166,7 @@ gst_structure_validate_name (const gchar * name)
s = &name[1];
while (*s && (g_ascii_isalnum (*s) || strchr ("/-_.:+ ", *s) != NULL))
s++;
- if (*s != '\0') {
+ if (G_UNLIKELY (*s != '\0')) {
GST_WARNING ("Invalid character '%c' at offset %lu in structure name: %s",
*s, ((gulong) s - (gulong) name), name);
return FALSE;
@@ -519,14 +519,14 @@ gst_structure_set_valist (GstStructure * structure,
type = va_arg (varargs, GType);
- if (type == G_TYPE_DATE) {
+ if (G_UNLIKELY (type == G_TYPE_DATE)) {
g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
type = GST_TYPE_DATE;
}
g_value_init (&field.value, type);
G_VALUE_COLLECT (&field.value, varargs, 0, &err);
- if (err) {
+ if (G_UNLIKELY (err)) {
g_critical ("%s", err);
return;
}
@@ -589,14 +589,14 @@ gst_structure_id_set_valist (GstStructure * structure,
type = va_arg (varargs, GType);
- if (type == G_TYPE_DATE) {
+ if (G_UNLIKELY (type == G_TYPE_DATE)) {
g_warning ("Don't use G_TYPE_DATE, use GST_TYPE_DATE instead\n");
type = GST_TYPE_DATE;
}
g_value_init (&field.value, type);
G_VALUE_COLLECT (&field.value, varargs, 0, &err);
- if (err) {
+ if (G_UNLIKELY (err)) {
g_critical ("%s", err);
return;
}
@@ -682,7 +682,7 @@ gst_structure_set_field (GstStructure * structure, GstStructureField * field)
for (i = 0; i < len; i++) {
f = GST_STRUCTURE_FIELD (structure, i);
- if (f->name == field->name) {
+ if (G_UNLIKELY (f->name == field->name)) {
g_value_unset (&f->value);
memcpy (f, field, sizeof (GstStructureField));
return;
@@ -706,7 +706,7 @@ gst_structure_id_get_field (const GstStructure * structure, GQuark field_id)
for (i = 0; i < len; i++) {
field = GST_STRUCTURE_FIELD (structure, i);
- if (field->name == field_id)
+ if (G_UNLIKELY (field->name == field_id))
return field;
}
@@ -979,7 +979,7 @@ gst_structure_foreach (const GstStructure * structure,
field = GST_STRUCTURE_FIELD (structure, i);
ret = func (field->name, &field->value, user_data);
- if (!ret)
+ if (G_UNLIKELY (!ret))
return FALSE;
}
@@ -1830,7 +1830,7 @@ gst_structure_parse_simple_string (gchar * str, gchar ** end)
{
char *s = str;
- while (GST_ASCII_IS_STRING (*s)) {
+ while (G_LIKELY (GST_ASCII_IS_STRING (*s))) {
s++;
}
@@ -1853,14 +1853,14 @@ gst_structure_parse_field (gchar * str,
while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
s++;
name = s;
- if (!gst_structure_parse_simple_string (s, &name_end))
+ if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &name_end)))
return FALSE;
s = name_end;
while (g_ascii_isspace (*s) || (s[0] == '\\' && g_ascii_isspace (s[1])))
s++;
- if (*s != '=')
+ if (G_UNLIKELY (*s != '='))
return FALSE;
s++;
@@ -1869,7 +1869,8 @@ gst_structure_parse_field (gchar * str,
field->name = g_quark_from_string (name);
*name_end = c;
- if (!gst_structure_parse_value (s, &s, &field->value, G_TYPE_INVALID))
+ if (G_UNLIKELY (!gst_structure_parse_value (s, &s, &field->value,
+ G_TYPE_INVALID)))
return FALSE;
*after = s;
@@ -1900,12 +1901,12 @@ gst_structure_parse_value (gchar * str,
while (g_ascii_isspace (*s))
s++;
type_name = s;
- if (!gst_structure_parse_simple_string (s, &type_end))
+ if (G_UNLIKELY (!gst_structure_parse_simple_string (s, &type_end)))
return FALSE;
s = type_end;
while (g_ascii_isspace (*s))
s++;
- if (*s != ')')
+ if (G_UNLIKELY (*s != ')'))
return FALSE;
s++;
while (g_ascii_isspace (*s))
@@ -1998,7 +1999,7 @@ gst_structure_from_string (const gchar * string, gchar ** end)
r++;
name = r;
- if (!gst_structure_parse_string (r, &w, &r)) {
+ if (G_UNLIKELY (!gst_structure_parse_string (r, &w, &r))) {
GST_WARNING ("Failed to parse structure string");
goto error;
}
@@ -2024,7 +2025,7 @@ gst_structure_from_string (const gchar * string, gchar ** end)
/* accept \0 as end delimiter */
break;
}
- if (*r != ',') {
+ if (G_UNLIKELY (*r != ',')) {
GST_WARNING ("Failed to find delimiter, r=%s", r);
goto error;
}
@@ -2034,7 +2035,7 @@ gst_structure_from_string (const gchar * string, gchar ** end)
r++;
memset (&field, 0, sizeof (field));
- if (!gst_structure_parse_field (r, &r, &field))
+ if (G_UNLIKELY (!gst_structure_parse_field (r, &r, &field)))
goto error;
gst_structure_set_field (structure, &field);
} while (TRUE);