mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-30 15:31:34 +00:00
builder: Small optimization
Use g_object_setv where we can. It would be much nicer if we could pass the pspecs we already have, and avoid having GObject look them up again.
This commit is contained in:
parent
5c3bb42612
commit
138fd6f0f3
106
gtk/gtkbuilder.c
106
gtk/gtkbuilder.c
@ -459,7 +459,6 @@ typedef struct
|
||||
{
|
||||
GPtrArray *names;
|
||||
GArray *values;
|
||||
guint len;
|
||||
} ObjectProperties;
|
||||
|
||||
|
||||
@ -468,8 +467,6 @@ object_properties_init (ObjectProperties *self)
|
||||
{
|
||||
self->names = NULL;
|
||||
self->values = NULL;
|
||||
|
||||
self->len = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -483,8 +480,6 @@ object_properties_destroy (ObjectProperties *self)
|
||||
|
||||
if (self->values)
|
||||
g_array_unref (self->values);
|
||||
|
||||
self->len = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
@ -493,10 +488,8 @@ object_properties_add (ObjectProperties *self,
|
||||
const GValue *value)
|
||||
{
|
||||
if (!self->names)
|
||||
self->names = g_ptr_array_sized_new (8);
|
||||
|
||||
if (!self->values)
|
||||
{
|
||||
self->names = g_ptr_array_sized_new (8);
|
||||
self->values = g_array_sized_new (FALSE, FALSE, sizeof (GValue), 8);
|
||||
g_array_set_clear_func (self->values, (GDestroyNotify) g_value_unset);
|
||||
}
|
||||
@ -505,8 +498,6 @@ object_properties_add (ObjectProperties *self,
|
||||
g_array_append_vals (self->values, value, 1);
|
||||
|
||||
g_assert (self->names->len == self->values->len);
|
||||
|
||||
self->len += 1;
|
||||
}
|
||||
|
||||
static const char *
|
||||
@ -751,9 +742,6 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
ObjectProperties parameters, construct_parameters;
|
||||
GObject *obj;
|
||||
int i;
|
||||
GtkBuildableIface *iface;
|
||||
gboolean custom_set_property;
|
||||
GtkBuildable *buildable;
|
||||
GParamFlags param_filter_flags;
|
||||
|
||||
g_assert (info->type != G_TYPE_INVALID);
|
||||
@ -821,7 +809,7 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
builder,
|
||||
info->id);
|
||||
g_assert (obj != NULL);
|
||||
if (construct_parameters.len > 0)
|
||||
if (construct_parameters.names->len > 0)
|
||||
g_warning ("Can't pass in construct-only parameters to %s", info->id);
|
||||
}
|
||||
else if (info->parent &&
|
||||
@ -836,7 +824,7 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
object_properties_destroy (&construct_parameters);
|
||||
return NULL;
|
||||
}
|
||||
if (construct_parameters.len > 0)
|
||||
if (construct_parameters.names)
|
||||
g_warning ("Can't pass in construct-only parameters to %s", childname);
|
||||
g_object_ref (obj);
|
||||
}
|
||||
@ -844,9 +832,9 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
{
|
||||
ensure_special_construct_parameters (builder, info->type, &construct_parameters);
|
||||
|
||||
if (construct_parameters.len > 0)
|
||||
if (construct_parameters.names)
|
||||
obj = g_object_new_with_properties (info->type,
|
||||
construct_parameters.len,
|
||||
construct_parameters.names->len,
|
||||
(const char **) construct_parameters.names->pdata,
|
||||
(GValue *) construct_parameters.values->data);
|
||||
else
|
||||
@ -869,9 +857,12 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
}
|
||||
object_properties_destroy (&construct_parameters);
|
||||
|
||||
custom_set_property = FALSE;
|
||||
buildable = NULL;
|
||||
iface = NULL;
|
||||
if (parameters.names)
|
||||
{
|
||||
GtkBuildableIface *iface = NULL;
|
||||
gboolean custom_set_property = FALSE;
|
||||
GtkBuildable *buildable = NULL;
|
||||
|
||||
if (GTK_IS_BUILDABLE (obj))
|
||||
{
|
||||
buildable = GTK_BUILDABLE (obj);
|
||||
@ -880,16 +871,14 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
custom_set_property = TRUE;
|
||||
}
|
||||
|
||||
for (i = 0; i < parameters.len; i++)
|
||||
if (custom_set_property)
|
||||
{
|
||||
for (i = 0; i < parameters.names->len; i++)
|
||||
{
|
||||
const char *name = object_properties_get_name (¶meters, i);
|
||||
const GValue *value = object_properties_get_value (¶meters, i);
|
||||
|
||||
if (custom_set_property)
|
||||
iface->set_buildable_property (buildable, builder, name, value);
|
||||
else
|
||||
g_object_set_property (obj, name, value);
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (GTK_DEBUG_CHECK (BUILDER))
|
||||
{
|
||||
@ -899,6 +888,29 @@ _gtk_builder_construct (GtkBuilder *builder,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_object_setv (obj,
|
||||
parameters.names->len,
|
||||
(const char **) parameters.names->pdata,
|
||||
(GValue *) parameters.values->data);
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (GTK_DEBUG_CHECK (BUILDER))
|
||||
{
|
||||
for (i = 0; i < parameters.names->len; i++)
|
||||
{
|
||||
const char *name = object_properties_get_name (¶meters, i);
|
||||
const GValue *value = object_properties_get_value (¶meters, i);
|
||||
char *str = g_strdup_value_contents (value);
|
||||
g_message ("set %s: %s = %s", info->id, name, str);
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
object_properties_destroy (¶meters);
|
||||
|
||||
if (info->bindings)
|
||||
@ -919,10 +931,6 @@ _gtk_builder_apply_properties (GtkBuilder *builder,
|
||||
GError **error)
|
||||
{
|
||||
ObjectProperties parameters;
|
||||
GtkBuildableIface *iface;
|
||||
GtkBuildable *buildable;
|
||||
gboolean custom_set_property;
|
||||
int i;
|
||||
|
||||
g_assert (info->object != NULL);
|
||||
g_assert (info->type != G_TYPE_INVALID);
|
||||
@ -936,10 +944,13 @@ _gtk_builder_apply_properties (GtkBuilder *builder,
|
||||
G_PARAM_CONSTRUCT_ONLY,
|
||||
¶meters, NULL);
|
||||
|
||||
if (parameters.names)
|
||||
{
|
||||
GtkBuildableIface *iface = NULL;
|
||||
GtkBuildable *buildable = NULL;
|
||||
gboolean custom_set_property = FALSE;
|
||||
int i;
|
||||
|
||||
custom_set_property = FALSE;
|
||||
buildable = NULL;
|
||||
iface = NULL;
|
||||
if (GTK_IS_BUILDABLE (info->object))
|
||||
{
|
||||
buildable = GTK_BUILDABLE (info->object);
|
||||
@ -948,15 +959,13 @@ _gtk_builder_apply_properties (GtkBuilder *builder,
|
||||
custom_set_property = TRUE;
|
||||
}
|
||||
|
||||
for (i = 0; i < parameters.len; i++)
|
||||
if (custom_set_property)
|
||||
{
|
||||
for (i = 0; i < parameters.names->len; i++)
|
||||
{
|
||||
const char *name = object_properties_get_name (¶meters, i);
|
||||
const GValue *value = object_properties_get_value (¶meters, i);
|
||||
if (custom_set_property)
|
||||
iface->set_buildable_property (buildable, builder, name, value);
|
||||
else
|
||||
g_object_set_property (info->object, name, value);
|
||||
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (GTK_DEBUG_CHECK (BUILDER))
|
||||
{
|
||||
@ -966,6 +975,29 @@ _gtk_builder_apply_properties (GtkBuilder *builder,
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
g_object_setv (info->object,
|
||||
parameters.names->len,
|
||||
(const char **) parameters.names->pdata,
|
||||
(GValue *) parameters.values->data);
|
||||
#ifdef G_ENABLE_DEBUG
|
||||
if (GTK_DEBUG_CHECK (BUILDER))
|
||||
{
|
||||
for (i = 0; i < parameters.names->len; i++)
|
||||
{
|
||||
const char *name = object_properties_get_name (¶meters, i);
|
||||
const GValue *value = object_properties_get_value (¶meters, i);
|
||||
char *str = g_strdup_value_contents (value);
|
||||
g_message ("set %s: %s = %s", info->id, name, str);
|
||||
g_free (str);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
object_properties_destroy (¶meters);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user