mirror of
https://gitlab.gnome.org/GNOME/glib.git
synced 2025-01-27 06:26:15 +01:00
Merge branch 'gobject-speedups2' into 'main'
Avoid g_type_peek_value_table See merge request GNOME/glib!2674
This commit is contained in:
commit
7de0fcd628
@ -813,6 +813,7 @@ g_param_spec_types
|
|||||||
<INCLUDE>glib-object.h,gobject/gvaluecollector.h</INCLUDE>
|
<INCLUDE>glib-object.h,gobject/gvaluecollector.h</INCLUDE>
|
||||||
GTypeCValue
|
GTypeCValue
|
||||||
G_VALUE_COLLECT_INIT
|
G_VALUE_COLLECT_INIT
|
||||||
|
G_VALUE_COLLECT_INIT2
|
||||||
G_VALUE_COLLECT
|
G_VALUE_COLLECT
|
||||||
G_VALUE_COLLECT_SKIP
|
G_VALUE_COLLECT_SKIP
|
||||||
G_VALUE_LCOPY
|
G_VALUE_LCOPY
|
||||||
|
@ -2294,9 +2294,11 @@ g_object_new_valist (GType object_type,
|
|||||||
{
|
{
|
||||||
GObjectConstructParam params_stack[16];
|
GObjectConstructParam params_stack[16];
|
||||||
GValue values_stack[G_N_ELEMENTS (params_stack)];
|
GValue values_stack[G_N_ELEMENTS (params_stack)];
|
||||||
|
GTypeValueTable *vtabs_stack[G_N_ELEMENTS (params_stack)];
|
||||||
const gchar *name;
|
const gchar *name;
|
||||||
GObjectConstructParam *params = params_stack;
|
GObjectConstructParam *params = params_stack;
|
||||||
GValue *values = values_stack;
|
GValue *values = values_stack;
|
||||||
|
GTypeValueTable **vtabs = vtabs_stack;
|
||||||
guint n_params = 0;
|
guint n_params = 0;
|
||||||
guint n_params_alloc = G_N_ELEMENTS (params_stack);
|
guint n_params_alloc = G_N_ELEMENTS (params_stack);
|
||||||
|
|
||||||
@ -2321,14 +2323,17 @@ g_object_new_valist (GType object_type,
|
|||||||
n_params_alloc = G_N_ELEMENTS (params_stack) * 2u;
|
n_params_alloc = G_N_ELEMENTS (params_stack) * 2u;
|
||||||
params = g_new (GObjectConstructParam, n_params_alloc);
|
params = g_new (GObjectConstructParam, n_params_alloc);
|
||||||
values = g_new (GValue, n_params_alloc);
|
values = g_new (GValue, n_params_alloc);
|
||||||
|
vtabs = g_new (GTypeValueTable *, n_params_alloc);
|
||||||
memcpy (params, params_stack, sizeof (GObjectConstructParam) * n_params);
|
memcpy (params, params_stack, sizeof (GObjectConstructParam) * n_params);
|
||||||
memcpy (values, values_stack, sizeof (GValue) * n_params);
|
memcpy (values, values_stack, sizeof (GValue) * n_params);
|
||||||
|
memcpy (vtabs, vtabs_stack, sizeof (GTypeValueTable *) * n_params);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
n_params_alloc *= 2u;
|
n_params_alloc *= 2u;
|
||||||
params = g_realloc (params, sizeof (GObjectConstructParam) * n_params_alloc);
|
params = g_realloc (params, sizeof (GObjectConstructParam) * n_params_alloc);
|
||||||
values = g_realloc (values, sizeof (GValue) * n_params_alloc);
|
values = g_realloc (values, sizeof (GValue) * n_params_alloc);
|
||||||
|
vtabs = g_realloc (vtabs, sizeof (GTypeValueTable *) * n_params_alloc);
|
||||||
}
|
}
|
||||||
|
|
||||||
for (i = 0; i < n_params; i++)
|
for (i = 0; i < n_params; i++)
|
||||||
@ -2339,7 +2344,7 @@ g_object_new_valist (GType object_type,
|
|||||||
params[n_params].value = &values[n_params];
|
params[n_params].value = &values[n_params];
|
||||||
memset (&values[n_params], 0, sizeof (GValue));
|
memset (&values[n_params], 0, sizeof (GValue));
|
||||||
|
|
||||||
G_VALUE_COLLECT_INIT (&values[n_params], pspec->value_type, var_args, 0, &error);
|
G_VALUE_COLLECT_INIT2 (&values[n_params], vtabs[n_params], pspec->value_type, var_args, 0, &error);
|
||||||
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
@ -2356,12 +2361,19 @@ g_object_new_valist (GType object_type,
|
|||||||
object = g_object_new_internal (class, params, n_params);
|
object = g_object_new_internal (class, params, n_params);
|
||||||
|
|
||||||
while (n_params--)
|
while (n_params--)
|
||||||
g_value_unset (params[n_params].value);
|
{
|
||||||
|
/* We open-code g_value_unset() here to avoid the
|
||||||
|
* cost of looking up the GTypeValueTable again.
|
||||||
|
*/
|
||||||
|
if (vtabs[n_params]->value_free)
|
||||||
|
vtabs[n_params]->value_free (params[n_params].value);
|
||||||
|
}
|
||||||
|
|
||||||
if (G_UNLIKELY (n_params_alloc != G_N_ELEMENTS (params_stack)))
|
if (G_UNLIKELY (n_params_alloc != G_N_ELEMENTS (params_stack)))
|
||||||
{
|
{
|
||||||
g_free (params);
|
g_free (params);
|
||||||
g_free (values);
|
g_free (values);
|
||||||
|
g_free (vtabs);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -2516,6 +2528,7 @@ g_object_set_valist (GObject *object,
|
|||||||
GValue value = G_VALUE_INIT;
|
GValue value = G_VALUE_INIT;
|
||||||
GParamSpec *pspec;
|
GParamSpec *pspec;
|
||||||
gchar *error = NULL;
|
gchar *error = NULL;
|
||||||
|
GTypeValueTable *vtab;
|
||||||
|
|
||||||
pspec = g_param_spec_pool_lookup (pspec_pool,
|
pspec = g_param_spec_pool_lookup (pspec_pool,
|
||||||
name,
|
name,
|
||||||
@ -2525,8 +2538,7 @@ g_object_set_valist (GObject *object,
|
|||||||
if (!g_object_set_is_valid_property (object, pspec, name))
|
if (!g_object_set_is_valid_property (object, pspec, name))
|
||||||
break;
|
break;
|
||||||
|
|
||||||
G_VALUE_COLLECT_INIT (&value, pspec->value_type, var_args,
|
G_VALUE_COLLECT_INIT2 (&value, vtab, pspec->value_type, var_args, 0, &error);
|
||||||
0, &error);
|
|
||||||
if (error)
|
if (error)
|
||||||
{
|
{
|
||||||
g_warning ("%s: %s", G_STRFUNC, error);
|
g_warning ("%s: %s", G_STRFUNC, error);
|
||||||
@ -2537,7 +2549,12 @@ g_object_set_valist (GObject *object,
|
|||||||
|
|
||||||
consider_issuing_property_deprecation_warning (pspec);
|
consider_issuing_property_deprecation_warning (pspec);
|
||||||
object_set_property (object, pspec, &value, nqueue);
|
object_set_property (object, pspec, &value, nqueue);
|
||||||
g_value_unset (&value);
|
|
||||||
|
/* We open-code g_value_unset() here to avoid the
|
||||||
|
* cost of looking up the GTypeValueTable again.
|
||||||
|
*/
|
||||||
|
if (vtab->value_free)
|
||||||
|
vtab->value_free (&value);
|
||||||
|
|
||||||
name = va_arg (var_args, gchar*);
|
name = va_arg (var_args, gchar*);
|
||||||
}
|
}
|
||||||
|
@ -87,15 +87,38 @@ union _GTypeCValue
|
|||||||
*
|
*
|
||||||
* Since: 2.24
|
* Since: 2.24
|
||||||
*/
|
*/
|
||||||
#define G_VALUE_COLLECT_INIT(value, _value_type, var_args, flags, __error) \
|
#define G_VALUE_COLLECT_INIT(value, _value_type, var_args, flags, __error) \
|
||||||
|
G_STMT_START { \
|
||||||
|
GTypeValueTable *g_vci_vtab; \
|
||||||
|
G_VALUE_COLLECT_INIT2(value, g_vci_vtab, _value_type, var_args, flags, __error); \
|
||||||
|
} G_STMT_END
|
||||||
|
|
||||||
|
/**
|
||||||
|
* G_VALUE_COLLECT_INIT2:
|
||||||
|
* @value: a #GValue return location. @value must contain only 0 bytes.
|
||||||
|
* @g_vci_vtab: a #GTypeValueTable pointer that will be set to the value table
|
||||||
|
* for @_value_type
|
||||||
|
* @_value_type: the #GType to use for @value.
|
||||||
|
* @var_args: the va_list variable; it may be evaluated multiple times
|
||||||
|
* @flags: flags which are passed on to the collect_value() function of
|
||||||
|
* the #GTypeValueTable of @value.
|
||||||
|
* @__error: a #gchar** variable that will be modified to hold a g_new()
|
||||||
|
* allocated error messages if something fails
|
||||||
|
*
|
||||||
|
* A variant of G_VALUE_COLLECT_INIT() that provides the #GTypeValueTable
|
||||||
|
* to the caller.
|
||||||
|
*
|
||||||
|
* Since: 2.74
|
||||||
|
*/
|
||||||
|
#define G_VALUE_COLLECT_INIT2(value, g_vci_vtab, _value_type, var_args, flags, __error) \
|
||||||
G_STMT_START { \
|
G_STMT_START { \
|
||||||
GValue *g_vci_val = (value); \
|
GValue *g_vci_val = (value); \
|
||||||
guint g_vci_flags = (flags); \
|
guint g_vci_flags = (flags); \
|
||||||
GTypeValueTable *g_vci_vtab = g_type_value_table_peek (_value_type); \
|
const gchar *g_vci_collect_format; \
|
||||||
const gchar *g_vci_collect_format = g_vci_vtab->collect_format; \
|
|
||||||
GTypeCValue g_vci_cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
|
GTypeCValue g_vci_cvalues[G_VALUE_COLLECT_FORMAT_MAX_LENGTH] = { { 0, }, }; \
|
||||||
guint g_vci_n_values = 0; \
|
guint g_vci_n_values = 0; \
|
||||||
\
|
g_vci_vtab = g_type_value_table_peek (_value_type); \
|
||||||
|
g_vci_collect_format = g_vci_vtab->collect_format; \
|
||||||
g_vci_val->g_type = _value_type; /* value_meminit() from gvalue.c */ \
|
g_vci_val->g_type = _value_type; /* value_meminit() from gvalue.c */ \
|
||||||
while (*g_vci_collect_format) \
|
while (*g_vci_collect_format) \
|
||||||
{ \
|
{ \
|
||||||
|
Loading…
Reference in New Issue
Block a user