[gtk/wip/alexl/gtkbuilder-xml-preparse] Use pre-parsed xml for GtkBuilder resource files



commit b128e52915065d8b1fef23485b0e9c27988fba1d
Author: Alexander Larsson <alexl redhat com>
Date:   Mon Sep 10 05:09:12 2018 +0200

    Use pre-parsed xml for GtkBuilder resource files
    
    This enables the xml-preparser gresource option which
    runs the xml through g_markup_parser_context_record(), and saves
    the generated binary format instead of the xml. We then check
    for the magic marker in the GtkBuilder code so that this automatically
    uses g_markup_parser_context_replay() instead, to avoid any
    parsing. The binary format is also smaller.

 gtk/gen-gtk-gresources-xml.py |  2 +-
 gtk/gtkbuilderparser.c        | 15 +++++++++++++--
 2 files changed, 14 insertions(+), 3 deletions(-)
---
diff --git a/gtk/gen-gtk-gresources-xml.py b/gtk/gen-gtk-gresources-xml.py
index 440d0b75f0..cf9b4c32d5 100644
--- a/gtk/gen-gtk-gresources-xml.py
+++ b/gtk/gen-gtk-gresources-xml.py
@@ -57,7 +57,7 @@ for f in get_files('gesture', '.symbolic.png'):
 xml += '\n'
 
 for f in get_files('ui', '.ui'):
-  xml += '    <file preprocess=\'xml-stripblanks\'>ui/{0}</file>\n'.format(f)
+  xml += '    <file preprocess=\'xml-stripblanks,xml-preparse\'>ui/{0}</file>\n'.format(f)
 
 xml += '\n'
 
diff --git a/gtk/gtkbuilderparser.c b/gtk/gtkbuilderparser.c
index 94c5b8b6c1..dac4a75984 100644
--- a/gtk/gtkbuilderparser.c
+++ b/gtk/gtkbuilderparser.c
@@ -1269,8 +1269,19 @@ _gtk_builder_parser_parse_buffer (GtkBuilder   *builder,
                                           G_MARKUP_TREAT_CDATA_AS_TEXT,
                                           &data, NULL);
 
-  if (!g_markup_parse_context_parse (data.ctx, buffer, length, error))
-    goto out;
+  if (buffer[0] == 'G' &&
+      buffer[1] == 'M' &&
+      buffer[2] == 'U' &&
+      buffer[3] == 0)
+    {
+      if (!g_markup_parse_context_replay (data.ctx, buffer, length, error))
+        goto out;
+    }
+  else
+    {
+      if (!g_markup_parse_context_parse (data.ctx, buffer, length, error))
+        goto out;
+    }
 
   _gtk_builder_finish (builder);
   if (_gtk_builder_lookup_failed (builder, error))


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