diff --git a/libgnucash/engine/Split.c b/libgnucash/engine/Split.c index 4f74b37094..5b3ecd6a37 100644 --- a/libgnucash/engine/Split.c +++ b/libgnucash/engine/Split.c @@ -893,21 +893,32 @@ xaccSplitEqual(const Split *sa, const Split *sb, * xaccSplitListGetUniqueTransactions ********************************************************************/ GList * -xaccSplitListGetUniqueTransactions(const GList *splits) +xaccSplitListGetUniqueTransactionsReversed (const GList *splits) { - const GList *snode; + GHashTable *txn_hash = g_hash_table_new (NULL, NULL); GList *transList = NULL; + const GList *snode; - for(snode = splits; snode; snode = snode->next) + for (snode = splits; snode; snode = snode->next) { Transaction *trans = xaccSplitGetParent((Split *)(snode->data)); - GList *item = g_list_find (transList, trans); - if (item == NULL) - transList = g_list_append (transList, trans); + if (g_hash_table_contains (txn_hash, trans)) + continue; + + g_hash_table_insert (txn_hash, trans, NULL); + transList = g_list_prepend (transList, trans); } + g_hash_table_destroy (txn_hash); return transList; } + +GList * +xaccSplitListGetUniqueTransactions(const GList *splits) +{ + return g_list_reverse (xaccSplitListGetUniqueTransactionsReversed (splits)); +} + /*################## Added for Reg2 #################*/ diff --git a/libgnucash/engine/Split.h b/libgnucash/engine/Split.h index 7f2e2025f8..fffc8409cc 100644 --- a/libgnucash/engine/Split.h +++ b/libgnucash/engine/Split.h @@ -359,6 +359,7 @@ Split * xaccSplitLookup (const GncGUID *guid, QofBook *book); /*################## Added for Reg2 #################*/ /* Get a GList of unique transactions containing the given list of Splits. */ +GList *xaccSplitListGetUniqueTransactionsReversed (const GList *splits); GList *xaccSplitListGetUniqueTransactions(const GList *splits); /*################## Added for Reg2 #################*/ /** Add a peer split to this split's lot-split list.