diff options
author | Daniel Robertson <danlrobertson89@gmail.com> | 2015-09-07 18:43:31 -0400 |
---|---|---|
committer | Noel Grandin <noelgrandin@gmail.com> | 2015-09-15 06:28:56 +0000 |
commit | e9e5fee720eb72fe789651861f48982d3d87674d (patch) | |
tree | cd4cb143f019e0dfb5829b1bdb0facbcc49fdef5 | |
parent | ee7da352b885cfead32abb3fd111acead0c32816 (diff) |
tdf#62525 editeng: OutlinerParaObject
Convert the pimpled copy-on-write OutlinerParaObject class from
editeng to use ::o3tl::cow_wrapper using the default reference
counting policy.
Change-Id: I7009b9623d5be1bdf806ccaa6781cba82553c302
Reviewed-on: https://gerrit.libreoffice.org/18391
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r-- | editeng/source/outliner/outlobj.cxx | 164 | ||||
-rw-r--r-- | include/editeng/outlobj.hxx | 31 |
2 files changed, 81 insertions, 114 deletions
diff --git a/editeng/source/outliner/outlobj.cxx b/editeng/source/outliner/outlobj.cxx index cb4098898675..9b6512039ec0 100644 --- a/editeng/source/outliner/outlobj.cxx +++ b/editeng/source/outliner/outlobj.cxx @@ -32,169 +32,117 @@ #include <vcl/bitmap.hxx> #include <tools/stream.hxx> -#include <boost/intrusive_ptr.hpp> +#include <o3tl/cow_wrapper.hxx> #include <libxml/xmlwriter.h> -/** - * This is the guts of OutlinerParaObject, refcounted and shared among - * multiple instances of OutlinerParaObject. - */ -struct OutlinerParaObjData +OutlinerParaObjData::OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) : + mpEditTextObject(pEditTextObject), + maParagraphDataVector(rParagraphDataVector), + mbIsEditDoc(bIsEditDoc) { - // data members - EditTextObject* mpEditTextObject; - ParagraphDataVector maParagraphDataVector; - bool mbIsEditDoc; - - // refcounter - mutable size_t mnRefCount; - - // constuctor - OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) : - mpEditTextObject(pEditTextObject), - maParagraphDataVector(rParagraphDataVector), - mbIsEditDoc(bIsEditDoc), - mnRefCount(0) - { - if( maParagraphDataVector.empty() && (pEditTextObject->GetParagraphCount() != 0) ) - maParagraphDataVector.resize(pEditTextObject->GetParagraphCount()); - } - - OutlinerParaObjData( const OutlinerParaObjData& r ) : - mpEditTextObject(r.mpEditTextObject->Clone()), - maParagraphDataVector(r.maParagraphDataVector), - mbIsEditDoc(r.mbIsEditDoc), - mnRefCount(0) - {} - - // destructor - ~OutlinerParaObjData() - { - delete mpEditTextObject; - } - - bool operator==(const OutlinerParaObjData& rCandidate) const - { - return (*mpEditTextObject == *rCandidate.mpEditTextObject - && maParagraphDataVector == rCandidate.maParagraphDataVector - && mbIsEditDoc == rCandidate.mbIsEditDoc); - } - - // #i102062# - bool isWrongListEqual(const OutlinerParaObjData& rCompare) const - { - return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject); - } -}; + if( maParagraphDataVector.empty() && (pEditTextObject->GetParagraphCount() != 0) ) + maParagraphDataVector.resize(pEditTextObject->GetParagraphCount()); +} -inline void intrusive_ptr_add_ref(const OutlinerParaObjData* p) +OutlinerParaObjData::OutlinerParaObjData( const OutlinerParaObjData& r ): + mpEditTextObject(r.mpEditTextObject->Clone()), + maParagraphDataVector(r.maParagraphDataVector), + mbIsEditDoc(r.mbIsEditDoc) { - ++p->mnRefCount; } -inline void intrusive_ptr_release(const OutlinerParaObjData* p) +OutlinerParaObjData::~OutlinerParaObjData() { - --p->mnRefCount; - if (!p->mnRefCount) - delete p; + delete mpEditTextObject; } -struct OutlinerParaObject::Impl +bool OutlinerParaObjData::operator==(const OutlinerParaObjData& rCandidate) const { - typedef boost::intrusive_ptr<OutlinerParaObjData> DataRef; - DataRef mxData; - - Impl( const EditTextObject& rTextObj, const ParagraphDataVector& rParaData, bool bIsEditDoc ) : - mxData(new OutlinerParaObjData(rTextObj.Clone(), rParaData, bIsEditDoc)) {} - - explicit Impl(const EditTextObject& rTextObj) : - mxData(new OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) {} - - Impl( const Impl& r ) : mxData(r.mxData) {} - - ~Impl() {} -}; + return (*mpEditTextObject == *rCandidate.mpEditTextObject + && maParagraphDataVector == rCandidate.maParagraphDataVector + && mbIsEditDoc == rCandidate.mbIsEditDoc); +} -void OutlinerParaObject::ImplMakeUnique() +bool OutlinerParaObjData::isWrongListEqual(const OutlinerParaObjData& rCompare) const { - mpImpl->mxData.reset(new OutlinerParaObjData(*mpImpl->mxData)); + return mpEditTextObject->isWrongListEqual(*rCompare.mpEditTextObject); } OutlinerParaObject::OutlinerParaObject( const EditTextObject& rTextObj, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) : - mpImpl(new Impl(rTextObj, rParagraphDataVector, bIsEditDoc)) {} + mpImpl(OutlinerParaObjData(rTextObj.Clone(), rParagraphDataVector, bIsEditDoc)) +{ +} OutlinerParaObject::OutlinerParaObject( const EditTextObject& rTextObj ) : - mpImpl(new Impl(rTextObj)) + mpImpl(OutlinerParaObjData(rTextObj.Clone(), ParagraphDataVector(), true)) { } OutlinerParaObject::OutlinerParaObject( const OutlinerParaObject& r ) : - mpImpl(new Impl(*r.mpImpl)) {} + mpImpl(r.mpImpl) +{ +} OutlinerParaObject::~OutlinerParaObject() { - delete mpImpl; } OutlinerParaObject& OutlinerParaObject::operator=( const OutlinerParaObject& r ) { - mpImpl->mxData = r.mpImpl->mxData; + mpImpl = r.mpImpl; return *this; } bool OutlinerParaObject::operator==( const OutlinerParaObject& r ) const { - if (r.mpImpl->mxData.get() == mpImpl->mxData.get()) - { - return true; - } - - return (*r.mpImpl->mxData == *mpImpl->mxData); + return r.mpImpl == mpImpl; } // #i102062# bool OutlinerParaObject::isWrongListEqual( const OutlinerParaObject& r ) const { - if (r.mpImpl->mxData.get() == mpImpl->mxData.get()) + if (r.mpImpl.same_object(mpImpl)) { return true; } - return mpImpl->mxData->isWrongListEqual(*r.mpImpl->mxData); + return mpImpl->isWrongListEqual(*r.mpImpl); } sal_uInt16 OutlinerParaObject::GetOutlinerMode() const { - return mpImpl->mxData->mpEditTextObject->GetUserType(); + return mpImpl->mpEditTextObject->GetUserType(); } void OutlinerParaObject::SetOutlinerMode(sal_uInt16 nNew) { - if (mpImpl->mxData->mpEditTextObject->GetUserType() != nNew) + // create a const pointer to avoid an early call to + // make_unique() in the dereference of mpImpl + const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl; + if ( ( *pImpl )->mpEditTextObject->GetUserType() != nNew ) { - ImplMakeUnique(); - mpImpl->mxData->mpEditTextObject->SetUserType(nNew); + mpImpl->mpEditTextObject->SetUserType(nNew); } } bool OutlinerParaObject::IsVertical() const { - return mpImpl->mxData->mpEditTextObject->IsVertical(); + return mpImpl->mpEditTextObject->IsVertical(); } void OutlinerParaObject::SetVertical(bool bNew) { - if (mpImpl->mxData->mpEditTextObject->IsVertical() != bNew) + const ::o3tl::cow_wrapper< OutlinerParaObjData >* pImpl = &mpImpl; + if ( ( *pImpl )->mpEditTextObject->IsVertical() != bNew ) { - ImplMakeUnique(); - mpImpl->mxData->mpEditTextObject->SetVertical(bNew); + mpImpl->mpEditTextObject->SetVertical(bNew); } } sal_Int32 OutlinerParaObject::Count() const { - size_t nSize = mpImpl->mxData->maParagraphDataVector.size(); + size_t nSize = mpImpl->maParagraphDataVector.size(); if (nSize > EE_PARA_MAX_COUNT) { SAL_WARN( "editeng", "OutlinerParaObject::Count - overflow " << nSize); @@ -205,9 +153,9 @@ sal_Int32 OutlinerParaObject::Count() const sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const { - if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->mxData->maParagraphDataVector.size()) + if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->maParagraphDataVector.size()) { - return mpImpl->mxData->maParagraphDataVector[nPara].getDepth(); + return mpImpl->maParagraphDataVector[nPara].getDepth(); } else { @@ -217,19 +165,19 @@ sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const const EditTextObject& OutlinerParaObject::GetTextObject() const { - return *mpImpl->mxData->mpEditTextObject; + return *mpImpl->mpEditTextObject; } bool OutlinerParaObject::IsEditDoc() const { - return mpImpl->mxData->mbIsEditDoc; + return mpImpl->mbIsEditDoc; } const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const { - if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->mxData->maParagraphDataVector.size()) + if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->maParagraphDataVector.size()) { - return mpImpl->mxData->maParagraphDataVector[nIndex]; + return mpImpl->maParagraphDataVector[nIndex]; } else { @@ -241,22 +189,19 @@ const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) cons void OutlinerParaObject::ClearPortionInfo() { - ImplMakeUnique(); - mpImpl->mxData->mpEditTextObject->ClearPortionInfo(); + mpImpl->mpEditTextObject->ClearPortionInfo(); } bool OutlinerParaObject::ChangeStyleSheets(const OUString& rOldName, SfxStyleFamily eOldFamily, const OUString& rNewName, SfxStyleFamily eNewFamily) { - ImplMakeUnique(); - return mpImpl->mxData->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily); + return mpImpl->mpEditTextObject->ChangeStyleSheets(rOldName, eOldFamily, rNewName, eNewFamily); } void OutlinerParaObject::ChangeStyleSheetName(SfxStyleFamily eFamily, const OUString& rOldName, const OUString& rNewName) { - ImplMakeUnique(); - mpImpl->mxData->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName); + mpImpl->mpEditTextObject->ChangeStyleSheetName(eFamily, rOldName, rNewName); } void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewName, @@ -266,14 +211,13 @@ void OutlinerParaObject::SetStyleSheets(sal_uInt16 nLevel, const OUString& rNewN if(nCount) { - ImplMakeUnique(); sal_Int32 nDecrementer(nCount); - for(;nDecrementer;) + while(nDecrementer > 0) { if(GetDepth(--nDecrementer) == nLevel) { - mpImpl->mxData->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily); + mpImpl->mpEditTextObject->SetStyleSheet(nDecrementer, rNewName, rNewFamily); } } } diff --git a/include/editeng/outlobj.hxx b/include/editeng/outlobj.hxx index 39c2b3ea9e9e..eac443bdd92a 100644 --- a/include/editeng/outlobj.hxx +++ b/include/editeng/outlobj.hxx @@ -24,15 +24,38 @@ #include <editeng/editengdllapi.h> #include <rtl/ustring.hxx> #include <rsc/rscsfx.hxx> +#include <o3tl/cow_wrapper.hxx> class EditTextObject; -class EDITENG_DLLPUBLIC OutlinerParaObject +/** + * This is the guts of OutlinerParaObject, refcounted and shared among + * multiple instances of OutlinerParaObject. + */ +struct OutlinerParaObjData { - struct Impl; - Impl* mpImpl; + // data members + EditTextObject* mpEditTextObject; + ParagraphDataVector maParagraphDataVector; + bool mbIsEditDoc; + + // constuctor + OutlinerParaObjData( EditTextObject* pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ); + + OutlinerParaObjData( const OutlinerParaObjData& r ); + + // destructor + ~OutlinerParaObjData(); + + bool operator==(const OutlinerParaObjData& rCandidate) const; - void ImplMakeUnique(); + // #i102062# + bool isWrongListEqual(const OutlinerParaObjData& rCompare) const; +}; + +class EDITENG_DLLPUBLIC OutlinerParaObject +{ + ::o3tl::cow_wrapper< OutlinerParaObjData > mpImpl; public: // constructors/destructor |