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-21 15:19:55 +0000
commitb5be1688c06fbd56d0d1661e5eda2aec09582d68 (patch)
tree3890a87faa9327250249e5b5d33048463f7b2986
parentbd6ea9106e0539364e66c6dc6fb5f5f3b0878920 (diff)
downloadappstream-glib-b5be1688c06fbd56d0d1661e5eda2aec09582d68.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);