summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Stahl <mstahl@redhat.com>2013-08-13 18:39:08 +0200
committerCaolán McNamara <caolanm@redhat.com>2013-08-14 09:04:26 +0000
commita0e98a12f8979286f2418606cfa4f75fcbc63b6e (patch)
tree64d38745789452db8410c00a0f7dd60741c5610e
parent8bf69e2abf94b94afedeb0b7d7644e5626954122 (diff)
fdo#58040: sw: fine tune async word count
- count characters instead of paragraphs to better account for large or small paragraphs - start out with a relatively small value (5k chars) on the first run to quickly show something to the user (cherry picked from commit 91c8008051c0bb7905a6acd822d022e144f2941f) Conflicts: sw/inc/doc.hxx sw/source/core/doc/doc.cxx Change-Id: Ic4013545692f267aab39e084415d5d794bb5a4ca Reviewed-on: https://gerrit.libreoffice.org/5392 Reviewed-by: Tor Lillqvist <tml@iki.fi> Tested-by: Tor Lillqvist <tml@iki.fi> Reviewed-by: Caolán McNamara <caolanm@redhat.com> Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/inc/doc.hxx5
-rw-r--r--sw/source/core/doc/doc.cxx17
2 files changed, 12 insertions, 10 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 53fc21932a98..7f5488cf538f 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -2070,12 +2070,11 @@ private:
void CopyMasterFooter(const SwPageDesc &rChged, const SwFmtFooter &rFoot, SwPageDesc *pDesc, bool bLeft);
/** continue computing a chunk of document statistics
- * \param nTextNodes number of paragraphs to calculate before
- * exiting
+ * \param nChars number of characters to count before exiting
*
* returns false when there is no more to calculate
*/
- bool IncrementalDocStatCalculate(long nTextNodes = 250);
+ bool IncrementalDocStatCalculate(long nChars);
/// Our own 'StatsUpdateTimer' calls the following method
DECL_LINK( DoIdleStatsUpdate, Timer * );
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index b71288c1a1ea..ad191619a800 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1684,22 +1684,25 @@ void SwDoc::CalculatePagePairsForProspectPrinting(
}
// returns true while there is more to do
-bool SwDoc::IncrementalDocStatCalculate( long nTextNodes )
+bool SwDoc::IncrementalDocStatCalculate(long nChars)
{
pDocStat->Reset();
pDocStat->nPara = 0; // default is 1!
SwNode* pNd;
// This is the inner loop - at least while the paras are dirty.
- for( sal_uLong i = GetNodes().Count(); i > 0 && nTextNodes > 0; )
+ for( sal_uLong i = GetNodes().Count(); i > 0 && nChars > 0; )
{
switch( ( pNd = GetNodes()[ --i ])->GetNodeType() )
{
case ND_TEXTNODE:
{
+ long const nOldChars(pDocStat->nChar);
SwTxtNode *pTxt = static_cast< SwTxtNode * >( pNd );
if( pTxt->CountWords( *pDocStat, 0, pTxt->GetTxt().Len() ) )
- nTextNodes--;
+ {
+ nChars -= (pDocStat->nChar - nOldChars);
+ }
break;
}
case ND_TABLENODE: ++pDocStat->nTbl; break;
@@ -1771,13 +1774,13 @@ bool SwDoc::IncrementalDocStatCalculate( long nTextNodes )
SwFieldType *pType = GetSysFldType(RES_DOCSTATFLD);
pType->UpdateFlds();
- return nTextNodes <= 0;
+ return nChars <= 0;
}
IMPL_LINK( SwDoc, DoIdleStatsUpdate, Timer *, pTimer )
{
(void)pTimer;
- if( IncrementalDocStatCalculate( 1000 ) )
+ if (IncrementalDocStatCalculate(32000))
aStatsUpdateTimer.Start();
SwView* pView = GetDocShell() ? GetDocShell()->GetView() : NULL;
@@ -1792,10 +1795,10 @@ void SwDoc::UpdateDocStat( bool bCompleteAsync )
{
if (!bCompleteAsync)
{
- while (IncrementalDocStatCalculate()) {}
+ while (IncrementalDocStatCalculate(5000)) {}
aStatsUpdateTimer.Stop();
}
- else if (IncrementalDocStatCalculate())
+ else if (IncrementalDocStatCalculate(5000))
aStatsUpdateTimer.Start();
}
}