diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-19 14:49:08 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-10-19 20:38:54 +0200 |
commit | ed3d2e9863c11a36756466d907fa7fa8ecb726d0 (patch) | |
tree | 4c238adc3c358c858f129434a0b99076f5b8f644 | |
parent | 7855c29b4d40a64b73ad30c3f1f94a81cd61bf7a (diff) |
use std::unique_ptr in SwDocUpdateField
Change-Id: I9d6eba5e2714a29fd3a2ad301298ad8590a4af36
Reviewed-on: https://gerrit.libreoffice.org/43549
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | sw/source/core/doc/docfld.cxx | 25 | ||||
-rw-r--r-- | sw/source/core/inc/docfld.hxx | 7 |
2 files changed, 12 insertions, 20 deletions
diff --git a/sw/source/core/doc/docfld.cxx b/sw/source/core/doc/docfld.cxx index dcbc666ccfde..90c44f70ab60 100644 --- a/sw/source/core/doc/docfld.cxx +++ b/sw/source/core/doc/docfld.cxx @@ -776,7 +776,7 @@ void SwDocUpdateField::InsDelFieldInFieldLst( bool bIns, const SwTextField& rFie { if( !bIns ) // if list is present and deleted return; // don't do a thing - pFieldSortLst = new SetGetExpFields; + pFieldSortLst.reset(new SetGetExpFields); } if( bIns ) // insert anew: @@ -805,8 +805,7 @@ void SwDocUpdateField::MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode ) void SwDocUpdateField::MakeFieldList_( SwDoc& rDoc, int eGetMode ) { // new version: walk all fields of the attribute pool - delete pFieldSortLst; - pFieldSortLst = new SetGetExpFields; + pFieldSortLst.reset(new SetGetExpFields); // consider and unhide sections // with hide condition, only in mode GETFLD_ALL (<eGetMode == GETFLD_ALL>) @@ -1104,8 +1103,8 @@ void SwDocUpdateField::InsertFieldType( const SwFieldType& rType ) if( !pFnd ) { SwCalcFieldType* pNew = new SwCalcFieldType( sFieldName, &rType ); - pNew->pNext.reset( aFieldTypeTable[ n ] ); - aFieldTypeTable[ n ] = pNew; + pNew->pNext.reset( aFieldTypeTable[ n ].release() ); + aFieldTypeTable[ n ].reset(pNew); } } } @@ -1134,14 +1133,13 @@ void SwDocUpdateField::RemoveFieldType( const SwFieldType& rType ) SwHash* pFnd = Find( sFieldName, GetFieldTypeTable(), TBLSZ, &n ); if( pFnd ) { - if( aFieldTypeTable[ n ] == pFnd ) + if( aFieldTypeTable[ n ].get() == pFnd ) { - aFieldTypeTable[ n ] = static_cast<SwCalcFieldType*>(pFnd->pNext.release()); - delete pFnd; + aFieldTypeTable[ n ].reset(static_cast<SwCalcFieldType*>(pFnd->pNext.release())); } else { - SwHash* pPrev = aFieldTypeTable[ n ]; + SwHash* pPrev = aFieldTypeTable[ n ].get(); while( pPrev->pNext.get() != pFnd ) pPrev = pPrev->pNext.get(); pPrev->pNext = std::move(pFnd->pNext); @@ -1152,23 +1150,16 @@ void SwDocUpdateField::RemoveFieldType( const SwFieldType& rType ) } SwDocUpdateField::SwDocUpdateField(SwDoc* pDoc) - : pFieldSortLst(nullptr) - , nNodes(0) + : nNodes(0) , nFieldLstGetMode(0) , pDocument(pDoc) , bInUpdateFields(false) , bFieldsDirty(false) - { - memset( aFieldTypeTable, 0, sizeof( aFieldTypeTable ) ); } SwDocUpdateField::~SwDocUpdateField() { - delete pFieldSortLst; - - for(SwCalcFieldType* p : aFieldTypeTable) - delete p; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/source/core/inc/docfld.hxx b/sw/source/core/inc/docfld.hxx index 5410ed76f52a..9979d557a8ee 100644 --- a/sw/source/core/inc/docfld.hxx +++ b/sw/source/core/inc/docfld.hxx @@ -24,6 +24,7 @@ #include <doc.hxx> #include <IDocumentTimerAccess.hxx> #include <o3tl/sorted_vector.hxx> +#include <memory> class SwTextField; class SwIndex; @@ -131,8 +132,8 @@ const int GETFLD_EXPAND = 2; class SwDocUpdateField { - SetGetExpFields* pFieldSortLst; // current field list for calculation - SwCalcFieldType* aFieldTypeTable[ TBLSZ ]; + std::unique_ptr<SetGetExpFields> pFieldSortLst; // current field list for calculation + std::unique_ptr<SwCalcFieldType> aFieldTypeTable[ TBLSZ ]; sal_uLong nNodes; // if the node count is different sal_uInt8 nFieldLstGetMode; @@ -149,7 +150,7 @@ public: SwDocUpdateField(SwDoc* pDocument); ~SwDocUpdateField(); - const SetGetExpFields* GetSortLst() const { return pFieldSortLst; } + const SetGetExpFields* GetSortLst() const { return pFieldSortLst.get(); } void MakeFieldList( SwDoc& rDoc, bool bAll, int eGetMode ); |