[gtk] GtkWidget: Precompile template xml on class creation



commit 73042bfc54ded75d3a4894bbbcece0d6e30a1e07
Author: Alexander Larsson <alexl redhat com>
Date:   Thu Aug 29 16:19:33 2019 +0200

    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.

 gtk/gtkwidget.c | 22 +++++++++++++++++++++-
 1 file changed, 21 insertions(+), 1 deletion(-)
---
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);
 }
 
 /**


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]