structure: micro-optimise some getters

Avoid checking the GType of the value twice (once on our side and
once in g_value_get_*()) by by-passing g_value_get() and accessing
the GValue structure directly.
This commit is contained in:
Tim-Philipp Müller 2009-12-17 19:45:31 +00:00
parent 17c98e3510
commit 4cdf375b1a
2 changed files with 32 additions and 13 deletions

View file

@ -122,6 +122,24 @@ gboolean gst_registry_binary_write_cache (GstRegistry * registry, const char *
extern gboolean _gst_disable_registry_cache;
#endif
/* provide inline gst_g_value_get_foo_unchecked(), used in gststructure.c */
#define DEFINE_INLINE_G_VALUE_GET_UNCHECKED(ret_type,name_type,v_field) \
static inline ret_type \
gst_g_value_get_##name_type##_unchecked (const GValue *value) \
{ \
return value->data[0].v_field; \
}
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gboolean,boolean,v_int)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint,int,v_int)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint,uint,v_uint)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gint64,int64,v_int64)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(guint64,uint64,v_uint64)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gfloat,float,v_float)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(gdouble,double,v_double)
DEFINE_INLINE_G_VALUE_GET_UNCHECKED(const gchar *,string,v_pointer)
/*** debugging categories *****************************************************/
#ifndef GST_REMOVE_GST_DEBUG

View file

@ -1147,7 +1147,7 @@ gst_structure_get_boolean (const GstStructure * structure,
if (!G_VALUE_HOLDS_BOOLEAN (&field->value))
return FALSE;
*value = g_value_get_boolean (&field->value);
*value = gst_g_value_get_boolean_unchecked (&field->value);
return TRUE;
}
@ -1183,7 +1183,7 @@ gst_structure_get_int (const GstStructure * structure,
if (!G_VALUE_HOLDS_INT (&field->value))
return FALSE;
*value = g_value_get_int (&field->value);
*value = gst_g_value_get_int_unchecked (&field->value);
return TRUE;
}
@ -1221,7 +1221,7 @@ gst_structure_get_uint (const GstStructure * structure,
if (!G_VALUE_HOLDS_UINT (&field->value))
return FALSE;
*value = g_value_get_uint (&field->value);
*value = gst_g_value_get_uint_unchecked (&field->value);
return TRUE;
}
@ -1335,7 +1335,7 @@ gst_structure_get_clock_time (const GstStructure * structure,
if (!G_VALUE_HOLDS_UINT64 (&field->value))
return FALSE;
*value = g_value_get_uint64 (&field->value);
*value = gst_g_value_get_uint64_unchecked (&field->value);
return TRUE;
}
@ -1371,7 +1371,7 @@ gst_structure_get_double (const GstStructure * structure,
if (!G_VALUE_HOLDS_DOUBLE (&field->value))
return FALSE;
*value = g_value_get_double (&field->value);
*value = gst_g_value_get_double_unchecked (&field->value);
return TRUE;
}
@ -1407,7 +1407,7 @@ gst_structure_get_string (const GstStructure * structure,
if (!G_VALUE_HOLDS_STRING (&field->value))
return NULL;
return g_value_get_string (&field->value);
return gst_g_value_get_string_unchecked (&field->value);
}
/**
@ -1787,13 +1787,14 @@ gst_structure_parse_range (gchar * s, gchar ** after, GValue * value,
if (G_VALUE_TYPE (&value1) == G_TYPE_DOUBLE) {
range_type = GST_TYPE_DOUBLE_RANGE;
g_value_init (value, range_type);
gst_value_set_double_range (value, g_value_get_double (&value1),
g_value_get_double (&value2));
gst_value_set_double_range (value,
gst_g_value_get_double_unchecked (&value1),
gst_g_value_get_double_unchecked (&value2));
} else if (G_VALUE_TYPE (&value1) == G_TYPE_INT) {
range_type = GST_TYPE_INT_RANGE;
g_value_init (value, range_type);
gst_value_set_int_range (value, g_value_get_int (&value1),
g_value_get_int (&value2));
gst_value_set_int_range (value, gst_g_value_get_int_unchecked (&value1),
gst_g_value_get_int_unchecked (&value2));
} else if (G_VALUE_TYPE (&value1) == GST_TYPE_FRACTION) {
range_type = GST_TYPE_FRACTION_RANGE;
g_value_init (value, range_type);
@ -2196,7 +2197,7 @@ gst_structure_fixate_field_nearest_int (GstStructure * structure,
for (i = 0; i < n; i++) {
list_value = gst_value_list_get_value (value, i);
if (G_VALUE_TYPE (list_value) == G_TYPE_INT) {
int x = g_value_get_int (list_value);
int x = gst_g_value_get_int_unchecked (list_value);
if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
best_index = i;
@ -2260,7 +2261,7 @@ gst_structure_fixate_field_nearest_double (GstStructure * structure,
for (i = 0; i < n; i++) {
list_value = gst_value_list_get_value (value, i);
if (G_VALUE_TYPE (list_value) == G_TYPE_DOUBLE) {
double x = g_value_get_double (list_value);
double x = gst_g_value_get_double_unchecked (list_value);
if (best_index == -1 || (ABS (target - x) < ABS (target - best))) {
best_index = i;
@ -2314,7 +2315,7 @@ gst_structure_fixate_field_boolean (GstStructure * structure,
for (i = 0; i < n; i++) {
list_value = gst_value_list_get_value (value, i);
if (G_VALUE_TYPE (list_value) == G_TYPE_BOOLEAN) {
gboolean x = g_value_get_boolean (list_value);
gboolean x = gst_g_value_get_boolean_unchecked (list_value);
if (best_index == -1 || x == target) {
best_index = i;