From 75b6d14455db5c96711becef4719e26697bd7f21 Mon Sep 17 00:00:00 2001 From: Christian Stimming Date: Tue, 1 Jan 2019 13:39:56 +0100 Subject: [PATCH] Speed-up of dealing with account_imap lists: Replace g_list_append with _prepend and subsequent _reverse. This is glib's suggested way of dealing with GList in more optimized way, as g_list_append will have to traverse the list until the end. --- libgnucash/engine/Account.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index 9b770f24c8..3d60cdfd05 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -5555,7 +5555,7 @@ build_non_bayes (const char *key, const GValue *value, gpointer user_data) imapInfo_node->category = g_strdup (imapInfo->category); imapInfo_node->count = g_strdup (" "); - imapInfo->list = g_list_append (imapInfo->list, imapInfo_node); + imapInfo->list = g_list_prepend (imapInfo->list, imapInfo_node); g_free (guid_string); } @@ -5594,7 +5594,7 @@ build_bayes (const char *key, KvpValue * value, GncImapInfo & imapInfo) imap_node->match_string = g_strdup (std::get <1> (parsed_key).c_str ()); imap_node->category = g_strdup(" "); imap_node->count = g_strdup_printf ("%" G_GINT64_FORMAT, count); - imapInfo.list = g_list_append (imapInfo.list, imap_node); + imapInfo.list = g_list_prepend (imapInfo.list, imap_node); } GList * @@ -5605,7 +5605,7 @@ gnc_account_imap_get_info_bayes (Account *acc) * of data about which we care. */ GncImapInfo imapInfo {acc, nullptr}; qof_instance_foreach_slot_prefix (QOF_INSTANCE (acc), IMAP_FRAME_BAYES, &build_bayes, imapInfo); - return imapInfo.list; + return g_list_reverse(imapInfo.list); } GList * @@ -5630,7 +5630,7 @@ gnc_account_imap_get_info (Account *acc, const char *category) qof_instance_foreach_slot (QOF_INSTANCE(acc), IMAP_FRAME, category, build_non_bayes, &imapInfo); } - return imapInfo.list; + return g_list_reverse(imapInfo.list); } /*******************************************************************************/