From 50e9e70592e7984f79ff9b40149f17c65560b25f Mon Sep 17 00:00:00 2001 From: Christopher Lam Date: Tue, 7 Feb 2023 23:59:36 +0800 Subject: [PATCH] [import-backend] don't search GHashTable twice search acct_id_hash once for dest_acct --- gnucash/import-export/import-backend.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/gnucash/import-export/import-backend.cpp b/gnucash/import-export/import-backend.cpp index 23df1f6012..b90a029f77 100644 --- a/gnucash/import-export/import-backend.cpp +++ b/gnucash/import-export/import-backend.cpp @@ -1017,12 +1017,16 @@ gboolean gnc_import_exists_online_id (Transaction *trans, GHashTable* acct_id_ha // Create a hash per account of a hash of all split IDs. Then the // test below will be fast if we have many transactions to import. auto dest_acct = xaccSplitGetAccount (source_split); - if (!g_hash_table_contains (acct_id_hash, dest_acct)) - g_hash_table_insert (acct_id_hash, dest_acct, - hash_account_online_ids (dest_acct)); - auto online_id_exists = g_hash_table_contains ( - static_cast(g_hash_table_lookup (acct_id_hash, dest_acct)), - source_online_id); + + auto online_id_hash = static_cast(g_hash_table_lookup (acct_id_hash, dest_acct)); + + if (!online_id_hash) + { + online_id_hash = hash_account_online_ids (dest_acct); + g_hash_table_insert (acct_id_hash, dest_acct, online_id_hash); + } + + auto online_id_exists = g_hash_table_contains (online_id_hash, source_online_id); /* If it does, abort the process for this transaction, since it is already in the system. */