GtkWidget: Precompile template xml on class creation

Ideally we will precompile during build and store the result in the
resource, but if that doesn't happen at least we will only parse
the xml once.
This commit is contained in:
Alexander Larsson
2019-08-29 16:19:33 +02:00
committed by Matthias Clasen
parent ff23397701
commit 73042bfc54

View File

@@ -12227,12 +12227,32 @@ void
gtk_widget_class_set_template (GtkWidgetClass *widget_class,
GBytes *template_bytes)
{
GBytes *data = NULL;
g_return_if_fail (GTK_IS_WIDGET_CLASS (widget_class));
g_return_if_fail (widget_class->priv->template == NULL);
g_return_if_fail (template_bytes != NULL);
widget_class->priv->template = g_slice_new0 (GtkWidgetTemplate);
widget_class->priv->template->data = g_bytes_ref (template_bytes);
if (!_gtk_buildable_parser_is_precompiled (g_bytes_get_data (template_bytes, NULL), g_bytes_get_size (template_bytes)))
{
GError *error = NULL;
data = _gtk_buildable_parser_precompile (g_bytes_get_data (template_bytes, NULL),
g_bytes_get_size (template_bytes),
&error);
if (data == NULL)
{
g_warning ("Failed to precompile template for class %s: %s", G_OBJECT_CLASS_NAME (widget_class), error->message);
g_error_free (error);
}
}
if (data)
widget_class->priv->template->data = data;
else
widget_class->priv->template->data = g_bytes_ref (template_bytes);
}
/**