mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-02-17 11:45:25 +00:00
gst/gstcaps.c: Callgrind micro optimisations.
Original commit message from CVS: * gst/gstcaps.c: (gst_caps_copy), (_gst_caps_free), (gst_caps_merge_structure), (gst_caps_get_structure), (gst_caps_copy_nth), (gst_caps_set_simple), (gst_caps_set_simple_valist), (gst_caps_is_fixed), (gst_caps_is_equal_fixed), (gst_caps_intersect), (gst_caps_subtract), (gst_caps_normalize), (gst_caps_do_simplify), (gst_caps_to_string): Callgrind micro optimisations. Avoid array bounds checks and force inline of trivial function. * gst/gstobject.c: (gst_object_set_name_default): -1 is equivalent to letting glib to the strlen but then there is more room for optimisations and it's not our fault. * gst/gststructure.c: (gst_structure_id_empty_new_with_size): no need to clear the array, we're cool. * gst/gstvalue.c: (gst_type_is_fixed), (gst_value_is_fixed): The most common _is_fixed() check is done on fundamental glib base types so we check this first instead of doing a huge amount of useless GST_TYPE_ARRAY calls.
This commit is contained in:
parent
812640dd18
commit
18aeb9a41e
5 changed files with 61 additions and 24 deletions
24
ChangeLog
24
ChangeLog
|
@ -1,3 +1,27 @@
|
|||
2008-11-06 Wim Taymans <wim.taymans@collabora.co.uk>
|
||||
|
||||
* gst/gstcaps.c: (gst_caps_copy), (_gst_caps_free),
|
||||
(gst_caps_merge_structure), (gst_caps_get_structure),
|
||||
(gst_caps_copy_nth), (gst_caps_set_simple),
|
||||
(gst_caps_set_simple_valist), (gst_caps_is_fixed),
|
||||
(gst_caps_is_equal_fixed), (gst_caps_intersect),
|
||||
(gst_caps_subtract), (gst_caps_normalize), (gst_caps_do_simplify),
|
||||
(gst_caps_to_string):
|
||||
Callgrind micro optimisations.
|
||||
Avoid array bounds checks and force inline of trivial function.
|
||||
|
||||
* gst/gstobject.c: (gst_object_set_name_default):
|
||||
-1 is equivalent to letting glib to the strlen but then there is more
|
||||
room for optimisations and it's not our fault.
|
||||
|
||||
* gst/gststructure.c: (gst_structure_id_empty_new_with_size):
|
||||
no need to clear the array, we're cool.
|
||||
|
||||
* gst/gstvalue.c: (gst_type_is_fixed), (gst_value_is_fixed):
|
||||
The most common _is_fixed() check is done on fundamental glib base
|
||||
types so we check this first instead of doing a huge amount of
|
||||
useless GST_TYPE_ARRAY calls.
|
||||
|
||||
2008-11-06 Wim Taymans <wim.taymans@collabora.co.uk>
|
||||
|
||||
* gst/gstevent.h:
|
||||
|
|
|
@ -91,6 +91,12 @@
|
|||
#define IS_WRITABLE(caps) \
|
||||
(g_atomic_int_get (&(caps)->refcount) == 1)
|
||||
|
||||
/* quick way to get a caps structure at an index without doing a type or array
|
||||
* length check */
|
||||
#define gst_caps_get_structure_unchecked(caps, index) \
|
||||
((GstStructure *)g_ptr_array_index ((caps)->structs, (index)))
|
||||
|
||||
|
||||
/* lock to protect multiple invocations of static caps to caps conversion */
|
||||
G_LOCK_DEFINE_STATIC (static_caps_lock);
|
||||
|
||||
|
@ -272,7 +278,7 @@ gst_caps_copy (const GstCaps * caps)
|
|||
newcaps->flags = caps->flags;
|
||||
|
||||
for (i = 0; i < caps->structs->len; i++) {
|
||||
structure = gst_caps_get_structure (caps, i);
|
||||
structure = gst_caps_get_structure_unchecked (caps, i);
|
||||
gst_caps_append_structure (newcaps, gst_structure_copy (structure));
|
||||
}
|
||||
|
||||
|
@ -289,7 +295,7 @@ _gst_caps_free (GstCaps * caps)
|
|||
* don't bother testing. */
|
||||
|
||||
for (i = 0; i < caps->structs->len; i++) {
|
||||
structure = (GstStructure *) gst_caps_get_structure (caps, i);
|
||||
structure = (GstStructure *) gst_caps_get_structure_unchecked (caps, i);
|
||||
gst_structure_set_parent_refcount (structure, NULL);
|
||||
gst_structure_free (structure);
|
||||
}
|
||||
|
@ -743,7 +749,7 @@ gst_caps_merge_structure (GstCaps * caps, GstStructure * structure)
|
|||
#endif
|
||||
/* check each structure */
|
||||
for (i = caps->structs->len - 1; i >= 0; i--) {
|
||||
structure1 = gst_caps_get_structure (caps, i);
|
||||
structure1 = gst_caps_get_structure_unchecked (caps, i);
|
||||
/* if structure is a subset of structure1, then skip it */
|
||||
if (gst_caps_structure_is_subset (structure1, structure)) {
|
||||
unique = FALSE;
|
||||
|
@ -797,7 +803,7 @@ gst_caps_get_structure (const GstCaps * caps, guint index)
|
|||
g_return_val_if_fail (GST_IS_CAPS (caps), NULL);
|
||||
g_return_val_if_fail (index < caps->structs->len, NULL);
|
||||
|
||||
return g_ptr_array_index (caps->structs, index);
|
||||
return gst_caps_get_structure_unchecked (caps, index);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -822,7 +828,7 @@ gst_caps_copy_nth (const GstCaps * caps, guint nth)
|
|||
newcaps->flags = caps->flags;
|
||||
|
||||
if (caps->structs->len > nth) {
|
||||
structure = gst_caps_get_structure (caps, nth);
|
||||
structure = gst_caps_get_structure_unchecked (caps, nth);
|
||||
gst_caps_append_structure (newcaps, gst_structure_copy (structure));
|
||||
}
|
||||
|
||||
|
@ -870,7 +876,7 @@ gst_caps_set_simple (GstCaps * caps, const char *field, ...)
|
|||
g_return_if_fail (caps->structs->len == 1);
|
||||
g_return_if_fail (IS_WRITABLE (caps));
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
structure = gst_caps_get_structure_unchecked (caps, 0);
|
||||
|
||||
va_start (var_args, field);
|
||||
gst_structure_set_valist (structure, field, var_args);
|
||||
|
@ -896,7 +902,7 @@ gst_caps_set_simple_valist (GstCaps * caps, const char *field, va_list varargs)
|
|||
g_return_if_fail (caps->structs->len == 1);
|
||||
g_return_if_fail (IS_WRITABLE (caps));
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
structure = gst_caps_get_structure_unchecked (caps, 0);
|
||||
|
||||
gst_structure_set_valist (structure, field, varargs);
|
||||
}
|
||||
|
@ -965,7 +971,7 @@ gst_caps_is_fixed (const GstCaps * caps)
|
|||
if (caps->structs->len != 1)
|
||||
return FALSE;
|
||||
|
||||
structure = gst_caps_get_structure (caps, 0);
|
||||
structure = gst_caps_get_structure_unchecked (caps, 0);
|
||||
|
||||
return gst_structure_foreach (structure, gst_caps_is_fixed_foreach, NULL);
|
||||
}
|
||||
|
@ -988,8 +994,8 @@ gst_caps_is_equal_fixed (const GstCaps * caps1, const GstCaps * caps2)
|
|||
g_return_val_if_fail (gst_caps_is_fixed (caps1), FALSE);
|
||||
g_return_val_if_fail (gst_caps_is_fixed (caps2), FALSE);
|
||||
|
||||
struct1 = gst_caps_get_structure (caps1, 0);
|
||||
struct2 = gst_caps_get_structure (caps2, 0);
|
||||
struct1 = gst_caps_get_structure_unchecked (caps1, 0);
|
||||
struct2 = gst_caps_get_structure_unchecked (caps2, 0);
|
||||
|
||||
if (struct1->name != struct2->name) {
|
||||
return FALSE;
|
||||
|
@ -1257,8 +1263,8 @@ gst_caps_intersect (const GstCaps * caps1, const GstCaps * caps2)
|
|||
/* now run the diagonal line, end condition is the left or bottom
|
||||
* border */
|
||||
while (k < caps2->structs->len) {
|
||||
struct1 = gst_caps_get_structure (caps1, j);
|
||||
struct2 = gst_caps_get_structure (caps2, k);
|
||||
struct1 = gst_caps_get_structure_unchecked (caps1, j);
|
||||
struct2 = gst_caps_get_structure_unchecked (caps2, k);
|
||||
|
||||
istruct = gst_caps_structure_intersect (struct1, struct2);
|
||||
|
||||
|
@ -1371,14 +1377,14 @@ gst_caps_subtract (const GstCaps * minuend, const GstCaps * subtrahend)
|
|||
|
||||
src = gst_caps_copy (minuend);
|
||||
for (i = 0; i < subtrahend->structs->len; i++) {
|
||||
sub = gst_caps_get_structure (subtrahend, i);
|
||||
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++) {
|
||||
min = gst_caps_get_structure (src, j);
|
||||
min = gst_caps_get_structure_unchecked (src, j);
|
||||
if (gst_structure_get_name_id (min) == gst_structure_get_name_id (sub)) {
|
||||
GSList *list;
|
||||
|
||||
|
@ -1499,7 +1505,7 @@ gst_caps_normalize (const GstCaps * caps)
|
|||
nf.caps = newcaps;
|
||||
|
||||
for (i = 0; i < newcaps->structs->len; i++) {
|
||||
nf.structure = gst_caps_get_structure (newcaps, i);
|
||||
nf.structure = gst_caps_get_structure_unchecked (newcaps, i);
|
||||
|
||||
while (!gst_structure_foreach (nf.structure,
|
||||
gst_caps_normalize_foreach, &nf));
|
||||
|
@ -1660,14 +1666,15 @@ gst_caps_do_simplify (GstCaps * caps)
|
|||
|
||||
start = caps->structs->len - 1;
|
||||
for (i = caps->structs->len - 1; i >= 0; i--) {
|
||||
simplify = gst_caps_get_structure (caps, i);
|
||||
simplify = gst_caps_get_structure_unchecked (caps, i);
|
||||
if (gst_structure_get_name_id (simplify) !=
|
||||
gst_structure_get_name_id (gst_caps_get_structure (caps, start)))
|
||||
gst_structure_get_name_id (gst_caps_get_structure_unchecked (caps,
|
||||
start)))
|
||||
start = i;
|
||||
for (j = start; j >= 0; j--) {
|
||||
if (j == i)
|
||||
continue;
|
||||
compare = gst_caps_get_structure (caps, j);
|
||||
compare = gst_caps_get_structure_unchecked (caps, j);
|
||||
if (gst_structure_get_name_id (simplify) !=
|
||||
gst_structure_get_name_id (compare)) {
|
||||
break;
|
||||
|
@ -1806,7 +1813,9 @@ 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++) {
|
||||
slen += STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure (caps, i));
|
||||
slen +=
|
||||
STRUCTURE_ESTIMATED_STRING_LEN (gst_caps_get_structure_unchecked (caps,
|
||||
i));
|
||||
}
|
||||
|
||||
s = g_string_sized_new (slen);
|
||||
|
@ -1818,7 +1827,7 @@ gst_caps_to_string (const GstCaps * caps)
|
|||
g_string_append_c (s, ' ');
|
||||
}
|
||||
|
||||
structure = gst_caps_get_structure (caps, i);
|
||||
structure = gst_caps_get_structure_unchecked (caps, i);
|
||||
priv_gst_structure_append_to_gstring (structure, s);
|
||||
}
|
||||
if (s->len && s->str[s->len - 1] == ';') {
|
||||
|
|
|
@ -621,7 +621,7 @@ gst_object_set_name_default (GstObject * object)
|
|||
if (strncmp (type_name, "Gst", 3) == 0)
|
||||
type_name += 3;
|
||||
tmp = g_strdup_printf ("%s%d", type_name, count);
|
||||
name = g_ascii_strdown (tmp, strlen (tmp));
|
||||
name = g_ascii_strdown (tmp, -1);
|
||||
g_free (tmp);
|
||||
|
||||
result = gst_object_set_name (object, name);
|
||||
|
|
|
@ -118,7 +118,7 @@ gst_structure_id_empty_new_with_size (GQuark quark, guint prealloc)
|
|||
structure->name = quark;
|
||||
structure->parent_refcount = NULL;
|
||||
structure->fields =
|
||||
g_array_sized_new (FALSE, TRUE, sizeof (GstStructureField), prealloc);
|
||||
g_array_sized_new (FALSE, FALSE, sizeof (GstStructureField), prealloc);
|
||||
|
||||
return structure;
|
||||
}
|
||||
|
|
|
@ -157,7 +157,8 @@ gst_type_is_fixed (GType type)
|
|||
}
|
||||
/* our fundamental types that are certainly not fixed */
|
||||
if (type == GST_TYPE_INT_RANGE || type == GST_TYPE_DOUBLE_RANGE ||
|
||||
type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE) {
|
||||
type == GST_TYPE_LIST || type == GST_TYPE_FRACTION_RANGE ||
|
||||
type == GST_TYPE_ARRAY) {
|
||||
return FALSE;
|
||||
}
|
||||
/* other (boxed) types that are fixed */
|
||||
|
@ -3341,6 +3342,9 @@ gst_value_is_fixed (const GValue * value)
|
|||
{
|
||||
GType type = G_VALUE_TYPE (value);
|
||||
|
||||
if (gst_type_is_fixed (type))
|
||||
return TRUE;
|
||||
|
||||
if (type == GST_TYPE_ARRAY) {
|
||||
gint size, n;
|
||||
const GValue *kid;
|
||||
|
@ -3355,7 +3359,7 @@ gst_value_is_fixed (const GValue * value)
|
|||
return TRUE;
|
||||
}
|
||||
|
||||
return gst_type_is_fixed (type);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/************
|
||||
|
|
Loading…
Reference in a new issue