From e80249ce2bbe90c54372e0fc5768aa0e9349f5ce Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Mon, 27 May 2024 07:03:42 +0800 Subject: [PATCH] [Account.cpp] gnc_account_remove_split shortcuts removing last split this speeds up book shutdown which empties the account splits in reverse chrono order. --- libgnucash/engine/Account.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/libgnucash/engine/Account.cpp b/libgnucash/engine/Account.cpp index e82fb8d9c0..94dd328681 100644 --- a/libgnucash/engine/Account.cpp +++ b/libgnucash/engine/Account.cpp @@ -2002,8 +2002,15 @@ gnc_account_remove_split (Account *acc, Split *s) if (!g_hash_table_remove (priv->splits_hash, s)) return false; - auto it = std::remove (priv->splits.begin(), priv->splits.end(), s); - priv->splits.erase (it, priv->splits.end()); + + // shortcut pruning the last element. this is the most common + // remove_split operation during UI or book shutdown. + if (s == priv->splits.back()) + priv->splits.pop_back(); + else + priv->splits.erase (std::remove (priv->splits.begin(), priv->splits.end(), s), + priv->splits.end()); + //FIXME: find better event type qof_event_gen(&acc->inst, QOF_EVENT_MODIFY, nullptr); // And send the account-based event, too