From: Alexander Larsson Date: Thu, 29 Aug 2019 14:19:33 +0000 (+0200) Subject: GtkWidget: Precompile template xml on class creation X-Git-Tag: archive/raspbian/4.4.1+ds1-2+rpi1^2~18^2~20^2~867 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=73042bfc54ded75d3a4894bbbcece0d6e30a1e07;p=gtk4.git 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. --- diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c index f1111277ba..18dde07f4c 100644 --- a/gtk/gtkwidget.c +++ b/gtk/gtkwidget.c @@ -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); } /**