diff --git a/src/engine/Account.c b/src/engine/Account.c index 7689d43623..79786106cf 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -681,7 +681,7 @@ xaccAccountRemoveSplit (Account *acc, Split *split) * value of such an account is the number of shares times the * * current share price. * * * - * Part of the complexity of this computatation stems from the fact * + * Part of the complexity of this computation stems from the fact * * xacc uses a double-entry system, meaning that one transaction * * appears in two accounts: one account is debited, and the other * * is credited. When the transaction represents a sale of shares, * @@ -700,7 +700,7 @@ price_xfer(Split * s, gnc_numeric share_count) { gnc_numeric temp; if(!gnc_numeric_zero_p(s->damount)) { temp = gnc_numeric_div(s->value, s->damount, - GNC_DENOM_AUTO, GNC_DENOM_EXACT); + 1000000, GNC_DENOM_LCD); temp = gnc_numeric_mul(share_count, temp, gnc_numeric_denom(s->value), GNC_RND_ROUND); @@ -726,6 +726,7 @@ xaccAccountRecomputeBalance (Account * acc) if(NULL == acc) return; if(acc->editlevel > 0) return; if(!acc->balance_dirty) return; + if(acc->do_free) return; dbalance = acc->starting_balance; dcleared_balance = acc->starting_cleared_balance; @@ -765,7 +766,7 @@ xaccAccountRecomputeBalance (Account * acc) split -> share_reconciled_balance = share_reconciled_balance; split -> balance = price_xfer(split, share_balance); split -> cleared_balance = price_xfer(split, share_cleared_balance); - split -> reconciled_balance = + split -> reconciled_balance = price_xfer(split, share_reconciled_balance); } else { diff --git a/src/engine/Group.c b/src/engine/Group.c index 9a063239fb..45f104d881 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -156,6 +156,26 @@ xaccAccountGroupCommitEdit (AccountGroup *grp) /********************************************************************\ \********************************************************************/ +void +xaccGroupMarkDoFree (AccountGroup *grp) +{ + GList *node; + + if (!grp) return; + + for (node = grp->accounts; node; node = node->next) + { + Account *account = node->data; + + account->do_free = TRUE; + + xaccGroupMarkDoFree (account->children); + } +} + +/********************************************************************\ +\********************************************************************/ + void xaccFreeAccountGroup (AccountGroup *grp) { diff --git a/src/engine/Group.h b/src/engine/Group.h index dce81626bd..f9cc3bc349 100644 --- a/src/engine/Group.h +++ b/src/engine/Group.h @@ -62,11 +62,15 @@ void xaccGroupMergeAccounts (AccountGroup *grp); * * The xaccGroupMarkNotSaved() subroutine will mark * the given group as not having been saved. + * + * The xaccGroupMarkDoFree() subroutine will mark + * all accounts in the group as being destroyed. */ gboolean xaccGroupNotSaved (AccountGroup *grp); void xaccGroupMarkSaved (AccountGroup *grp); void xaccGroupMarkNotSaved (AccountGroup *grp); +void xaccGroupMarkDoFree (AccountGroup *grp); /* * The xaccRemoveAccount() subroutine will remove the indicated diff --git a/src/engine/gnc-book.c b/src/engine/gnc-book.c index 55ddaa1023..9cae3cc44c 100644 --- a/src/engine/gnc-book.c +++ b/src/engine/gnc-book.c @@ -659,6 +659,10 @@ gnc_book_destroy (GNCBook *book) if (book->backend) g_free(book->backend); xaccGroupSetBackend (book->topgroup, NULL); + /* mark the accounts as being freed + * to avoid tons of balance recomputations. */ + xaccGroupMarkDoFree (book->topgroup); + xaccFreeAccountGroup (book->topgroup); book->topgroup = NULL; xaccLogEnable(); diff --git a/src/engine/kvp_frame.h b/src/engine/kvp_frame.h index 179b023785..62314a98d6 100644 --- a/src/engine/kvp_frame.h +++ b/src/engine/kvp_frame.h @@ -66,7 +66,7 @@ kvp_frame * kvp_frame_copy(const kvp_frame * frame); * associating it with 'key'. * The kvp_frame_set_slot_nc() routine puts the value (without copying * it) into the frame, associating it with 'key'. This routine is - * handy for aviding excess memory allocations & frees. + * handy for avoiding excess memory allocations & frees. */ void kvp_frame_set_slot(kvp_frame * frame, const char * key, const kvp_value * value); @@ -75,7 +75,7 @@ void kvp_frame_set_slot_nc(kvp_frame * frame, kvp_value * kvp_frame_get_slot(kvp_frame * frame, const char * key); -/* The kvp_frame_set_slot_path() routines walk the heirarchy, +/* The kvp_frame_set_slot_path() routines walk the hierarchy, * using the key falues to pick each branch. When the terminal node * is reached, the value is copied into it. */