[gtk/prop-list: 93/96] builderlistitemfactory: Precompile the xml
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/prop-list: 93/96] builderlistitemfactory: Precompile the xml
- Date: Tue, 24 Dec 2019 20:44:44 +0000 (UTC)
commit b1fdd77ede1f2062b77705bbb19171a09df71029
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Dec 23 18:23:59 2019 -0500
builderlistitemfactory: Precompile the xml
This is the one place where we can really take advantage
of precompiling, since we instantiate this template
over and over.
gtk/gtkbuilderlistitemfactory.c | 28 ++++++++++++++++++++++++++--
1 file changed, 26 insertions(+), 2 deletions(-)
---
diff --git a/gtk/gtkbuilderlistitemfactory.c b/gtk/gtkbuilderlistitemfactory.c
index 682b502dfb..527eca7765 100644
--- a/gtk/gtkbuilderlistitemfactory.c
+++ b/gtk/gtkbuilderlistitemfactory.c
@@ -22,6 +22,7 @@
#include "gtkbuilderlistitemfactory.h"
#include "gtkbuilder.h"
+#include "gtkbuilderprivate.h"
#include "gtkintl.h"
#include "gtklistitemfactoryprivate.h"
#include "gtklistitemprivate.h"
@@ -61,6 +62,7 @@ struct _GtkBuilderListItemFactory
GtkBuilderScope *scope;
GBytes *bytes;
+ GBytes *data;
char *resource;
};
@@ -100,8 +102,8 @@ gtk_builder_list_item_factory_setup (GtkListItemFactory *factory,
gtk_builder_set_scope (builder, self->scope);
if (!gtk_builder_extend_with_template (builder, G_OBJECT (list_item), GTK_TYPE_LIST_ITEM,
- (const gchar *)g_bytes_get_data (self->bytes, NULL),
- g_bytes_get_size (self->bytes),
+ (const gchar *)g_bytes_get_data (self->data, NULL),
+ g_bytes_get_size (self->data),
&error))
{
g_critical ("Error building template for list item: %s", error->message);
@@ -159,6 +161,27 @@ gtk_builder_list_item_factory_set_bytes (GtkBuilderListItemFactory *self,
}
self->bytes = g_bytes_ref (bytes);
+
+ if (!_gtk_buildable_parser_is_precompiled (g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes)))
+ {
+ GError *error = NULL;
+ GBytes *data;
+
+ data = _gtk_buildable_parser_precompile (g_bytes_get_data (bytes, NULL),
+ g_bytes_get_size (bytes),
+ &error);
+ if (data == NULL)
+ {
+ g_warning ("Failed to precompile template for GtkBuilderListItemFactory: %s", error->message);
+ g_error_free (error);
+ self->data = g_bytes_ref (bytes);
+ }
+ else
+ {
+ self->data = data;
+ }
+ }
+
return TRUE;
}
@@ -218,6 +241,7 @@ gtk_builder_list_item_factory_finalize (GObject *object)
g_clear_object (&self->scope);
g_bytes_unref (self->bytes);
+ g_bytes_unref (self->data);
g_free (self->resource);
G_OBJECT_CLASS (gtk_builder_list_item_factory_parent_class)->finalize (object);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]