diff options
author | Michael Stahl <mstahl@redhat.com> | 2013-08-13 18:39:08 +0200 |
---|---|---|
committer | Tor Lillqvist <tml@iki.fi> | 2013-08-14 06:56:06 +0000 |
commit | 5837861da958eeef66c5167e75ea388cb7053ea7 (patch) | |
tree | c2ce4ca004b2c8dc3cc9a636ed415d9d18e7db84 /sw | |
parent | 63162c960ae6f0d70740a6bba2cf225d2d8d3688 (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
Change-Id: Ic4013545692f267aab39e084415d5d794bb5a4ca
(cherry picked from commit 91c8008051c0bb7905a6acd822d022e144f2941f)
Reviewed-on: https://gerrit.libreoffice.org/5391
Reviewed-by: Tor Lillqvist <tml@iki.fi>
Tested-by: Tor Lillqvist <tml@iki.fi>
Diffstat (limited to 'sw')
-rw-r--r-- | sw/inc/doc.hxx | 5 | ||||
-rw-r--r-- | sw/source/core/doc/doc.cxx | 17 |
2 files changed, 12 insertions, 10 deletions
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx index 98a0c30972d3..12ab4765a469 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -2085,13 +2085,12 @@ 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 * \param bFields if stat. fields should be updated * * returns false when there is no more to calculate */ - bool IncrementalDocStatCalculate(long nTextNodes = 250, bool bFields = true); + bool IncrementalDocStatCalculate(long nChars, bool bFields = true); /// 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 f52766dcbed3..1993018a172f 100644 --- a/sw/source/core/doc/doc.cxx +++ b/sw/source/core/doc/doc.cxx @@ -1644,22 +1644,25 @@ void SwDoc::CalculatePagePairsForProspectPrinting( } // returns true while there is more to do -bool SwDoc::IncrementalDocStatCalculate( long nTextNodes, bool bFields ) +bool SwDoc::IncrementalDocStatCalculate(long nChars, bool bFields) { mpDocStat->Reset(); mpDocStat->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(mpDocStat->nChar); SwTxtNode *pTxt = static_cast< SwTxtNode * >( pNd ); if (pTxt->CountWords(*mpDocStat, 0, pTxt->GetTxt().getLength())) - nTextNodes--; + { + nChars -= (mpDocStat->nChar - nOldChars); + } break; } case ND_TABLENODE: ++mpDocStat->nTbl; break; @@ -1734,13 +1737,13 @@ bool SwDoc::IncrementalDocStatCalculate( long nTextNodes, bool bFields ) pType->UpdateFlds(); } - return nTextNodes <= 0; + return nChars <= 0; } IMPL_LINK( SwDoc, DoIdleStatsUpdate, Timer *, pTimer ) { (void)pTimer; - if( IncrementalDocStatCalculate( 1000 ) ) + if (IncrementalDocStatCalculate(32000)) maStatsUpdateTimer.Start(); SwView* pView = GetDocShell() ? GetDocShell()->GetView() : NULL; @@ -1755,10 +1758,10 @@ void SwDoc::UpdateDocStat( bool bCompleteAsync, bool bFields ) { if (!bCompleteAsync) { - while (IncrementalDocStatCalculate(250, bFields)) {} + while (IncrementalDocStatCalculate(5000, bFields)) {} maStatsUpdateTimer.Stop(); } - else if (IncrementalDocStatCalculate(250, bFields)) + else if (IncrementalDocStatCalculate(5000, bFields)) maStatsUpdateTimer.Start(); } } |