From 12096fd0f11e2d1280096352b71de70fb66f9892 Mon Sep 17 00:00:00 2001 From: Michael Stahl Date: Tue, 13 Aug 2013 18:39:08 +0200 Subject: fdo#58040: sw: fine tune async word count MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 Tested-by: Tor Lillqvist Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- sw/inc/doc.hxx | 5 ++--- 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 ed168699ce83..cdd8dae6b065 100644 --- a/sw/inc/doc.hxx +++ b/sw/inc/doc.hxx @@ -2074,12 +2074,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(); } } -- cgit v1.2.3