summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Hughes <richard@hughsie.com>2016-11-17 13:01:13 +0000
committerRichard Hughes <richard@hughsie.com>2016-11-18 20:22:31 +0000
commit25c51798f80dc3e5c32abf843c580488411761ec (patch)
tree2e6b977c53b59957663495fe6d35b4fe4287301a
parent91f24d49cd3eb5cb93a977af1b4b8f97742f674e (diff)
downloadappstream-glib-25c51798f80dc3e5c32abf843c580488411761ec.tar.gz
trivial: Don't split the text every time in the XML parsing hot path
This speeds up parsing to as good as pre-refcounted string time.
-rw-r--r--libappstream-glib/as-node.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/libappstream-glib/as-node.c b/libappstream-glib/as-node.c
index 6231367..0953ec2 100644
--- a/libappstream-glib/as-node.c
+++ b/libappstream-glib/as-node.c
@@ -506,6 +506,14 @@ as_node_reflow_text (const gchar *text, gssize text_len)
g_auto(GStrv) split = NULL;
g_autoptr(GString) tmp = NULL;
+ /* all on one line */
+ if (g_strstr_len (text, text_len, "\n") == NULL &&
+ !g_str_has_prefix (text, " ")) {
+ gsize len;
+ len = text_len >= 0 ? (gsize) text_len : strlen (text);
+ return as_ref_string_new_copy_with_length (text, len);
+ }
+
/* split the text into lines */
tmp = g_string_sized_new ((gsize) text_len + 1);
split = g_strsplit (text, "\n", -1);