[glib/wip/alexl/gmarkup-record: 2/2] glib-compile-resources: Add xml-preparse convert option
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [glib/wip/alexl/gmarkup-record: 2/2] glib-compile-resources: Add xml-preparse convert option
- Date: Wed, 12 Sep 2018 11:55:20 +0000 (UTC)
commit a83c8705d1c940ee6110c31940b66a3579187253
Author: Alexander Larsson <alexl redhat com>
Date: Mon Sep 10 05:01:25 2018 +0200
glib-compile-resources: Add xml-preparse convert option
This uses g_markup_parse_context_record() and is useful to pre-parse
GtkBuilder files for faster parsing.
gio/glib-compile-resources.c | 21 +++++++++++++++++++++
1 file changed, 21 insertions(+)
---
diff --git a/gio/glib-compile-resources.c b/gio/glib-compile-resources.c
index 6ce5aec4a..ceab02082 100644
--- a/gio/glib-compile-resources.c
+++ b/gio/glib-compile-resources.c
@@ -220,6 +220,7 @@ end_element (GMarkupParseContext *context,
gchar *key;
FileData *data = NULL;
char *tmp_file = NULL;
+ gboolean xml_preparse = FALSE;
file = state->string->str;
key = file;
@@ -283,6 +284,8 @@ end_element (GMarkupParseContext *context,
{
if (!strcmp (options[i], "xml-stripblanks"))
xml_stripblanks = TRUE;
+ else if (!strcmp (options[i], "xml-preparse"))
+ xml_preparse = TRUE;
else if (!strcmp (options[i], "to-pixdata"))
to_pixdata = TRUE;
else if (!strcmp (options[i], "json-stripblanks"))
@@ -465,6 +468,24 @@ end_element (GMarkupParseContext *context,
/* Include zero termination in content_size for uncompressed files (but not in size) */
data->content_size = data->size + 1;
+ if (xml_preparse)
+ {
+ GBytes *preparsed = g_markup_parse_context_record (G_MARKUP_TREAT_CDATA_AS_TEXT,
+ data->content, data->size, &my_error);
+ if (preparsed == NULL)
+ {
+ g_set_error (error, G_MARKUP_ERROR, G_MARKUP_ERROR_INVALID_CONTENT,
+ _("Error pre-parsing xml file %s: %s"),
+ real_file, my_error->message);
+ g_clear_error (&my_error);
+ goto cleanup;
+ }
+
+ g_free (data->content);
+ data->content = g_bytes_unref_to_data (preparsed, &data->size);
+ data->content_size = data->size;
+ }
+
if (state->compressed)
{
GOutputStream *out = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]