From b128e52915065d8b1fef23485b0e9c27988fba1d Mon Sep 17 00:00:00 2001 From: Alexander Larsson Date: Mon, 10 Sep 2018 05:09:12 +0200 Subject: 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 += ' ui/{0}\n'.format(f) + xml += ' ui/{0}\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)) -- cgit v1.2.1