From 141bf58dd3f131908c4e882fd31af1ac84ef4b0a Mon Sep 17 00:00:00 2001 From: Dave Peticolas Date: Fri, 4 Aug 2000 16:08:20 +0000 Subject: [PATCH] Bill Carlson's performance improvement patch. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@2631 57a11ea4-9604-0410-9ed3-97b8803252fd --- AUTHORS | 1 + doc/html/C/xacc-about.html | 4 ++++ src/engine/Account.c | 33 +++++++++++++++++++++++---------- src/engine/Group.c | 19 +++++++++++++++++++ 4 files changed, 47 insertions(+), 10 deletions(-) diff --git a/AUTHORS b/AUTHORS index 158a8ac5fc..6ef0f9359b 100644 --- a/AUTHORS +++ b/AUTHORS @@ -46,6 +46,7 @@ Per Bojsen several core dump fixes Terry Boldt financial calculator and expression parser Simon Britnell patch to RPM spec Christopher B. Browne for perl and lots of scheme +Bill Carlson performance improvements Graham Chapman for the xacc-rpts addon package George Chen for MS-Money QIF's & fixes Albert Chin-A-Young configure.in patch diff --git a/doc/html/C/xacc-about.html b/doc/html/C/xacc-about.html index 51a23bea96..7cbf9d7517 100644 --- a/doc/html/C/xacc-about.html +++ b/doc/html/C/xacc-about.html @@ -259,6 +259,10 @@ of changes to English documentation, and lots of guile code +
Bill Carlson
+ +
performance improvements
+
Graham Chapman
diff --git a/src/engine/Account.c b/src/engine/Account.c index 5308730408..f2ddbf92e9 100644 --- a/src/engine/Account.c +++ b/src/engine/Account.c @@ -441,29 +441,38 @@ xaccAccountInsertSplit ( Account *acc, Split *split ) /* Find the insertion point */ /* to get realy fancy, could use binary search. */ - for(i = 0; i < (acc->numSplits - 1);) { - if(xaccSplitDateOrder(&(oldsplits[i]), &split) > 0) { - break; - } else { - acc->splits[i] = oldsplits[i]; + /* but to get just a little fancy, see if it's after the last one */ + if ((acc->numSplits > 1) + && xaccSplitDateOrder(&split, &(oldsplits[acc->numSplits - 2])) > 0) { + i = acc->numSplits - 1; + memcpy (&acc->splits[0], &oldsplits[0], + (acc->numSplits-1) * sizeof (oldsplits[0])); + } + else { + for(i = 0; i < (acc->numSplits - 1);) { + if(xaccSplitDateOrder(&(oldsplits[i]), &split) > 0) { + break; + } else { + acc->splits[i] = oldsplits[i]; + } + i++; /* Don't put this in the loop guard! It'll go too far. */ } - i++; /* Don't put this in the loop guard! It'll go too far. */ } /* Insertion point is now i */ - + PINFO ("Insertion position is: %d\n", i); - + /* Move all the other splits down (this could be done faster with memmove)*/ for( j = acc->numSplits; j > i; j--) { acc->splits[j] = oldsplits[j - 1]; } - + /* Now insert the new split */ acc->splits[i] = split; /* make sure the array is NULL terminated */ acc->splits[acc->numSplits] = NULL; - + _free(oldsplits); } else { acc->numSplits ++; @@ -568,6 +577,10 @@ xaccAccountRecomputeBalance( Account * acc ) Split *split, *last_split = NULL; if( NULL == acc ) return; + /* + * if we are defering, defer! + */ + if (acc->open & ACC_DEFER_REBALANCE) return; if (0x0 == (ACC_INVALID_BALN & acc->changed)) return; acc->changed &= ~ACC_INVALID_BALN; diff --git a/src/engine/Group.c b/src/engine/Group.c index 49c748ba34..7d9f75eb75 100644 --- a/src/engine/Group.c +++ b/src/engine/Group.c @@ -81,6 +81,23 @@ xaccMallocAccountGroup( void ) /********************************************************************\ \********************************************************************/ +static void +xaccAccountGroupBeginEdit( AccountGroup *grp, int defer ) +{ + int i; + + if (NULL == grp) return; + + for(i = 0; i < grp->numAcc; i++ ) + { + xaccAccountBeginEdit(grp->account[i], defer); + xaccAccountGroupBeginEdit (grp->account[i]->children, defer); + } +} + +/********************************************************************\ +\********************************************************************/ + void xaccFreeAccountGroup( AccountGroup *grp ) { @@ -88,6 +105,8 @@ xaccFreeAccountGroup( AccountGroup *grp ) if (NULL == grp) return; + xaccAccountGroupBeginEdit (grp, 1); + for( i=0; inumAcc; i++ ) xaccFreeAccount( grp->account[i] );