Hi,
New version of the patch. I have added a method :
IDocumentStatistic::GetUpdatedDocStat wich check state before returning. I
left some UpdateDocStat but I will continue it later.
Sorry for the first patch.
2011/8/19 Caolán McNamara <caolanm@redhat.com>
On Wed, 2011-08-17 at 21:04 +0200, Arnaud Versini wrote:
Hi
This patch remove unnecessary parameter SwDocStat& rStat to the method
IDocumentStatistics::UpdateDocStat and also limit copy of SwDocStat
during file saving and statistic dialog.
There's a bug in the last hunk anyway,
{
SwDocStat aStat(pDocShell->GetDoc()->GetDocStat());
if(aStat.bModified)
- pDocShell->GetDoc()->UpdateDocStat( aStat );
+ pDocShell->GetDoc()->UpdateDocStat();
i.e. the "aStat" is a copy so after the UpdateDocStat is called, it's an
unchanged copy, not a reference to an updated SwDocStat like it used to
be, so a line or two later nValue = aStat.nChar will be wrong.
Is there a specific problem you're trying to fix here ?
This is only for refactoring, I've seen some things to change when I have
patched fdo#36931.
Looking through the DocStat stuff it looks a bit messy. Seems of it
appears to want to give access to the document statistics for a fast
query by some code that the stats need to be updated, and by other code
just to get the stats. And some bits fail to check for bModified and
force an update and some do. And the awesome rtf filter const_casts the
document doc stat and updates it directly.
This rtf filter will be replaced with GSoC?
If we want to refactor this then I suggest...
a) move "bModified" out of the SwDocStat and add something like bool
areStatsStale/statsNeedUpdating to IDocumentStatistics instead to query
this fact
I will do this for shells I think
b) have IDocumentStatistics::GetDocStat always return updated document
stats instead of having to get them, find out if they are stale and
update them if they are.
Done with a new method
That would probably avoid the problems of needing to directly call
UpdateDocStat for the general case where someone just wants to get
up-to-date stats, but allow any special cases of calling UpdateDocStat
when areStatsStale is true in order to force update of fields that
display the doc stats.
C.
Thanks
--
Arnaud Versini
From 96575b8208b60b2cec24879bff0c0e893b798dbc Mon Sep 17 00:00:00 2001
From: Arnaud Versini <arnaud.versini@gmail.com>
Date: Wed, 17 Aug 2011 20:27:25 +0200
Subject: [PATCH] Remove unecessary parameter to
IDocumentStatistics::UpdateDocStat()
---
sw/inc/IDocumentStatistics.hxx | 4 ++-
sw/inc/doc.hxx | 3 +-
sw/inc/editsh.hxx | 2 +-
sw/source/core/doc/doc.cxx | 54 ++++++++++++++++++++---------------
sw/source/core/edit/editsh.cxx | 6 ++--
sw/source/core/unocore/unofield.cxx | 3 +-
sw/source/filter/html/swhtml.cxx | 3 +-
sw/source/filter/xml/xmlexp.cxx | 13 +--------
sw/source/ui/app/docsh.cxx | 3 +-
sw/source/ui/dialog/docstdlg.cxx | 3 +-
sw/source/ui/shells/annotsh.cxx | 3 +-
sw/source/ui/shells/basesh.cxx | 3 +-
sw/source/ui/shells/drawsh.cxx | 4 +-
sw/source/ui/shells/drwtxtex.cxx | 4 +-
sw/source/ui/shells/frmsh.cxx | 4 +-
sw/source/ui/shells/textsh1.cxx | 4 +-
sw/source/ui/uno/unotxdoc.cxx | 4 +--
17 files changed, 56 insertions(+), 64 deletions(-)
diff --git a/sw/inc/IDocumentStatistics.hxx b/sw/inc/IDocumentStatistics.hxx
index 152d382..8bdebba 100644
--- a/sw/inc/IDocumentStatistics.hxx
+++ b/sw/inc/IDocumentStatistics.hxx
@@ -46,9 +46,11 @@
*/
virtual const SwDocStat &GetDocStat() const = 0;
+ virtual const SwDocStat &GetUpdatedDocStat() = 0;
+
virtual void SetDocStat(const SwDocStat& rStat) = 0;
- virtual void UpdateDocStat(SwDocStat& rStat) = 0;
+ virtual void UpdateDocStat() = 0;
protected:
virtual ~IDocumentStatistics() {};
diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 9e8f3a9..ead098d 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -899,8 +899,9 @@ public:
*/
virtual void DocInfoChgd();
virtual const SwDocStat &GetDocStat() const;
+ virtual const SwDocStat &GetUpdatedDocStat();
virtual void SetDocStat(const SwDocStat& rStat);
- virtual void UpdateDocStat(SwDocStat& rStat);
+ virtual void UpdateDocStat();
/** IDocumentState
*/
diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx
index 14ea40e..6666efb 100644
--- a/sw/inc/editsh.hxx
+++ b/sw/inc/editsh.hxx
@@ -374,7 +374,7 @@ public:
void SetUndoNoResetModified();
// Document - Statistics
- void UpdateDocStat( SwDocStat& rStat );
+ void UpdateDocStat();
void Insert(const SwTOXMark& rMark);
diff --git a/sw/source/core/doc/doc.cxx b/sw/source/core/doc/doc.cxx
index 8b1c82f..34d7a96 100644
--- a/sw/source/core/doc/doc.cxx
+++ b/sw/source/core/doc/doc.cxx
@@ -1073,6 +1073,15 @@ const SwDocStat& SwDoc::GetDocStat() const
return *pDocStat;
}
+const SwDocStat& SwDoc::GetUpdatedDocStat()
+{
+ if (pDocStat->bModified)
+ {
+ UpdateDocStat();
+ }
+ return *pDocStat;
+}
+
struct _PostItFld : public _SetGetExpFld
{
_PostItFld( const SwNodeIndex& rNdIdx, const SwTxtFld* pFld, const SwIndex* pIdx = 0 )
@@ -1707,14 +1716,14 @@ void SwDoc::CalculatePagePairsForProspectPrinting(
}
/*************************************************************************
- * void UpdateDocStat( const SwDocStat& rStat );
+ * void UpdateDocStat();
*************************************************************************/
-void SwDoc::UpdateDocStat( SwDocStat& rStat )
+void SwDoc::UpdateDocStat()
{
- if( rStat.bModified )
+ if( pDocStat->bModified )
{
- rStat.Reset();
- rStat.nPara = 0; // Default ist auf 1 !!
+ pDocStat->Reset();
+ pDocStat->nPara = 0; // Default ist auf 1 !!
SwNode* pNd;
for( sal_uLong i = GetNodes().Count(); i; )
@@ -1722,11 +1731,11 @@ void SwDoc::UpdateDocStat( SwDocStat& rStat )
switch( ( pNd = GetNodes()[ --i ])->GetNodeType() )
{
case ND_TEXTNODE:
- ((SwTxtNode*)pNd)->CountWords( rStat, 0, ((SwTxtNode*)pNd)->GetTxt().Len() );
+ ((SwTxtNode*)pNd)->CountWords( *pDocStat, 0, ((SwTxtNode*)pNd)->GetTxt().Len() );
break;
- case ND_TABLENODE: ++rStat.nTbl; break;
- case ND_GRFNODE: ++rStat.nGrf; break;
- case ND_OLENODE: ++rStat.nOLE; break;
+ case ND_TABLENODE: ++pDocStat->nTbl; break;
+ case ND_GRFNODE: ++pDocStat->nGrf; break;
+ case ND_OLENODE: ++pDocStat->nOLE; break;
case ND_SECTIONNODE: break;
}
}
@@ -1741,36 +1750,35 @@ void SwDoc::UpdateDocStat( SwDocStat& rStat )
{
SwPostItField const * const pField(
static_cast<SwPostItField const*>(pFmtFld->GetFld()));
- rStat.nAllPara += pField->GetNumberOfParagraphs();
+ pDocStat->nAllPara += pField->GetNumberOfParagraphs();
}
}
}
- rStat.nPage = GetCurrentLayout() ? GetCurrentLayout()->GetPageNum() : 0; //swmod
080218
- rStat.bModified = sal_False;
- SetDocStat( rStat );
+ pDocStat->nPage = GetCurrentLayout() ? GetCurrentLayout()->GetPageNum() : 0;
//swmod 080218
+ pDocStat->bModified = sal_False;
- com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aStat( rStat.nPage ? 8
: 7);
+ com::sun::star::uno::Sequence < com::sun::star::beans::NamedValue > aStat( pDocStat->nPage
? 8 : 7);
sal_Int32 n=0;
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("TableCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nTbl;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nTbl;
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ImageCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nGrf;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nGrf;
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ObjectCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nOLE;
- if ( rStat.nPage )
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nOLE;
+ if ( pDocStat->nPage )
{
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("PageCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nPage;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nPage;
}
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("ParagraphCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nPara;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nPara;
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("WordCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nWord;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nWord;
aStat[n].Name = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("CharacterCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nChar;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nChar;
aStat[n].Name =
::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("NonWhitespaceCharacterCount"));
- aStat[n++].Value <<= (sal_Int32)rStat.nCharExcludingSpaces;
+ aStat[n++].Value <<= (sal_Int32)pDocStat->nCharExcludingSpaces;
// For e.g. autotext documents there is no pSwgInfo (#i79945)
SfxObjectShell * const pObjShell( GetDocShell() );
diff --git a/sw/source/core/edit/editsh.cxx b/sw/source/core/edit/editsh.cxx
index 7968ef4..d13c8af 100644
--- a/sw/source/core/edit/editsh.cxx
+++ b/sw/source/core/edit/editsh.cxx
@@ -489,14 +489,14 @@ String SwEditShell::GetCurWord()
}
/****************************************************************************
- * void SwEditShell::UpdateDocStat( SwDocStat& rStat )
+ * void SwEditShell::UpdateDocStat()
****************************************************************************/
-void SwEditShell::UpdateDocStat( SwDocStat& rStat )
+void SwEditShell::UpdateDocStat( )
{
StartAllAction();
- GetDoc()->UpdateDocStat( rStat );
+ GetDoc()->UpdateDocStat( );
EndAllAction();
}
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 5ffd6f3..4206c76 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -2662,8 +2662,7 @@ void SwXTextFieldTypes::refresh(void) throw( uno::RuntimeException )
if(!IsValid())
throw uno::RuntimeException();
UnoActionContext aContext(GetDoc());
- SwDocStat aDocStat;
- GetDoc()->UpdateDocStat(aDocStat);
+ GetDoc()->UpdateDocStat();
GetDoc()->UpdateFlds(0, sal_False);
// call refresh listeners
diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx
index 45c7f95..9a8d77a 100644
--- a/sw/source/filter/html/swhtml.cxx
+++ b/sw/source/filter/html/swhtml.cxx
@@ -869,8 +869,7 @@ if( pSttNdIdx->GetIndex()+1 == pPam->GetBound( sal_False ).nNode.GetIndex() )
if( bUpdateDocStat )
{
- SwDocStat aStat( pDoc->GetDocStat() );
- pDoc->UpdateDocStat( aStat );
+ pDoc->UpdateDocStat();
}
}
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index 5f8fd91..d30528f 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -279,14 +279,8 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
SetExtended( bExtended );
- SwDocStat aDocStat( pDoc->GetDocStat() );
if( (getExportFlags() & EXPORT_META) != 0 )
{
- // Update doc stat, so that correct values are exported and
- // the progress works correctly.
- if( aDocStat.bModified )
- pDoc->UpdateDocStat( aDocStat );
-
SfxObjectShell* pObjSh = pDoc->GetDocShell();
if( pObjSh )
pObjSh->UpdateDocInfoForSave(); // update information
@@ -305,11 +299,6 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
// - page styles: 2 (TODO: not now!) + 2 for each paragraph
// - paragraph: 2 (1 for automatic styles and one for content)
- // If required, update doc stat, so that
- // the progress works correctly.
- if( aDocStat.bModified )
- pDoc->UpdateDocStat( aDocStat );
-
// count each item once, and then multiply by two to reach the
// figures given above
// The styles in pDoc also count the default style that never
@@ -320,7 +309,7 @@ sal_uInt32 SwXMLExport::exportDoc( enum XMLTokenEnum eClass )
nRef += pDoc->GetTxtFmtColls()->Count() - 1;
nRef *= 2; // for the above styles, xmloff will increment by 2!
// #i93174#: count all paragraphs for the progress bar
- nRef += aDocStat.nAllPara; // 1: only content, no autostyle
+ nRef += pDoc->GetUpdatedDocStat().nAllPara; // 1: only content, no autostyle
pProgress->SetReference( nRef );
pProgress->SetValue( 0 );
}
diff --git a/sw/source/ui/app/docsh.cxx b/sw/source/ui/app/docsh.cxx
index 0b3bec5..793b912 100644
--- a/sw/source/ui/app/docsh.cxx
+++ b/sw/source/ui/app/docsh.cxx
@@ -606,8 +606,7 @@ sal_Bool SwDocShell::ConvertTo( SfxMedium& rMedium )
}
// #i76360# Update document statistics
- SwDocStat aDocStat( pDoc->GetDocStat() );;
- pDoc->UpdateDocStat( aDocStat );
+ pDoc->UpdateDocStat();
CalcLayoutForOLEObjects(); // format for OLE objets
// #i62875#
diff --git a/sw/source/ui/dialog/docstdlg.cxx b/sw/source/ui/dialog/docstdlg.cxx
index 2b199b4..5dafb36 100644
--- a/sw/source/ui/dialog/docstdlg.cxx
+++ b/sw/source/ui/dialog/docstdlg.cxx
@@ -149,8 +149,7 @@ void SwDocStatPage::Update()
SwWait aWait( *pSh->GetDoc()->GetDocShell(), sal_True );
pSh->StartAction();
- aDocStat = pSh->GetDoc()->GetDocStat();
- pSh->GetDoc()->UpdateDocStat( aDocStat );
+ aDocStat = pSh->GetDoc()->GetUpdatedDocStat();
pSh->EndAction();
SetData(aDocStat);
diff --git a/sw/source/ui/shells/annotsh.cxx b/sw/source/ui/shells/annotsh.cxx
index 1753f9b..eeb6c77 100644
--- a/sw/source/ui/shells/annotsh.cxx
+++ b/sw/source/ui/shells/annotsh.cxx
@@ -412,12 +412,11 @@ void SwAnnotationShell::Exec( SfxRequest &rReq )
{
SwWrtShell &rSh = rView.GetWrtShell();
SwDocStat aCurr;
- SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
+ const SwDocStat& aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
{
SwWait aWait( *rView.GetDocShell(), sal_True );
rSh.StartAction();
rSh.CountWords( aCurr );
- rSh.UpdateDocStat( aDocStat );
rSh.EndAction();
}
diff --git a/sw/source/ui/shells/basesh.cxx b/sw/source/ui/shells/basesh.cxx
index 6bb2f67..4659fac 100644
--- a/sw/source/ui/shells/basesh.cxx
+++ b/sw/source/ui/shells/basesh.cxx
@@ -603,8 +603,7 @@ void SwBaseShell::Execute(SfxRequest &rReq)
break;
case FN_UPDATE_FIELDS:
{
- SwDocStat aDocStat;
- rSh.UpdateDocStat(aDocStat);
+ rSh.UpdateDocStat();
rSh.EndAllTblBoxEdit();
rSh.ViewShell::UpdateFlds(sal_True);
diff --git a/sw/source/ui/shells/drawsh.cxx b/sw/source/ui/shells/drawsh.cxx
index dcf352b..a4565d8 100644
--- a/sw/source/ui/shells/drawsh.cxx
+++ b/sw/source/ui/shells/drawsh.cxx
@@ -233,12 +233,12 @@ void SwDrawShell::Execute(SfxRequest &rReq)
case FN_WORDCOUNT_DIALOG:
{
SwDocStat aCurr;
- SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
+ const SwDocStat& aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
{
SwWait aWait( *GetView().GetDocShell(), sal_True );
rSh.StartAction();
rSh.CountWords( aCurr );
- rSh.UpdateDocStat( aDocStat );
+ rSh.UpdateDocStat();
rSh.EndAction();
}
diff --git a/sw/source/ui/shells/drwtxtex.cxx b/sw/source/ui/shells/drwtxtex.cxx
index 0deab44..c514f40 100644
--- a/sw/source/ui/shells/drwtxtex.cxx
+++ b/sw/source/ui/shells/drwtxtex.cxx
@@ -347,12 +347,12 @@ void SwDrawTextShell::Execute( SfxRequest &rReq )
case FN_WORDCOUNT_DIALOG:
{
SwDocStat aCurr;
- SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
+ const SwDocStat& aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
{
SwWait aWait( *GetView().GetDocShell(), sal_True );
rSh.StartAction();
rSh.CountWords( aCurr );
- rSh.UpdateDocStat( aDocStat );
+ rSh.UpdateDocStat();
rSh.EndAction();
}
diff --git a/sw/source/ui/shells/frmsh.cxx b/sw/source/ui/shells/frmsh.cxx
index 9763e08..489466a 100644
--- a/sw/source/ui/shells/frmsh.cxx
+++ b/sw/source/ui/shells/frmsh.cxx
@@ -419,12 +419,12 @@ void SwFrameShell::Execute(SfxRequest &rReq)
case FN_WORDCOUNT_DIALOG:
{
SwDocStat aCurr;
- SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
+ const SwDocStat& aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
{
SwWait aWait( *GetView().GetDocShell(), sal_True );
rSh.StartAction();
rSh.CountWords( aCurr );
- rSh.UpdateDocStat( aDocStat );
+ rSh.UpdateDocStat();
rSh.EndAction();
}
diff --git a/sw/source/ui/shells/textsh1.cxx b/sw/source/ui/shells/textsh1.cxx
index a7ff278..058c7c8 100644
--- a/sw/source/ui/shells/textsh1.cxx
+++ b/sw/source/ui/shells/textsh1.cxx
@@ -1280,12 +1280,12 @@ void SwTextShell::Execute(SfxRequest &rReq)
{
SwWrtShell &rSh = GetShell();
SwDocStat aCurr;
- SwDocStat aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
+ const SwDocStat& aDocStat( rSh.getIDocumentStatistics()->GetDocStat() );
{
SwWait aWait( *GetView().GetDocShell(), sal_True );
rSh.StartAction();
rSh.CountWords( aCurr );
- rSh.UpdateDocStat( aDocStat );
+ rSh.UpdateDocStat();
rSh.EndAction();
}
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index 418dbf0..18b8994 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -2020,9 +2020,7 @@ Any SwXTextDocument::getPropertyValue(const OUString& rPropertyName)
case WID_DOC_PARA_COUNT :
case WID_DOC_WORD_COUNT :
{
- SwDocStat aStat(pDocShell->GetDoc()->GetDocStat());
- if(aStat.bModified)
- pDocShell->GetDoc()->UpdateDocStat( aStat );
+ const SwDocStat& aStat(pDocShell->GetDoc()->GetUpdatedDocStat());
sal_Int32 nValue;
switch(pEntry->nWID)
{
--
1.7.5.4
Context
Privacy Policy |
Impressum (Legal Info) |
Copyright information: Unless otherwise specified, all text and images
on this website are licensed under the
Creative Commons Attribution-Share Alike 3.0 License.
This does not include the source code of LibreOffice, which is
licensed under the Mozilla Public License (
MPLv2).
"LibreOffice" and "The Document Foundation" are
registered trademarks of their corresponding registered owners or are
in actual use as trademarks in one or more countries. Their respective
logos and icons are also subject to international copyright laws. Use
thereof is explained in our
trademark policy.