diff options
author | Alexander Larsson <alexl@redhat.com> | 2018-09-10 05:09:12 +0200 |
---|---|---|
committer | Alexander Larsson <alexl@redhat.com> | 2018-09-10 05:09:12 +0200 |
commit | b128e52915065d8b1fef23485b0e9c27988fba1d (patch) | |
tree | 1c5331a52c659aa92606ac9418918420627a597d | |
parent | 005f932d13dafd01c9fcf7565be1a4fb9280228c (diff) | |
download | gtk+-wip/alexl/gtkbuilder-xml-preparse.tar.gz |
Use pre-parsed xml for GtkBuilder resource fileswip/alexl/gtkbuilder-xml-preparse
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.
-rw-r--r-- | gtk/gen-gtk-gresources-xml.py | 2 | ||||
-rw-r--r-- | 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)) |