From b5be1688c06fbd56d0d1661e5eda2aec09582d68 Mon Sep 17 00:00:00 2001 From: Richard Hughes Date: Thu, 17 Nov 2016 13:01:13 +0000 Subject: 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. --- libappstream-glib/as-node.c | 8 ++++++++ 1 file changed, 8 insertions(+) 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); -- cgit v1.2.1