editeng/source/items/numitem.cxx | 27 +++++++++++---------------- editeng/source/rtf/svxrtf.cxx | 24 ++++++++++-------------- include/editeng/numitem.hxx | 2 +- include/editeng/svxrtf.hxx | 5 +++-- 4 files changed, 25 insertions(+), 33 deletions(-)
New commits: commit add8b7099394e0754693af5a89d148ddc118182e Author: Noel Grandin <[email protected]> Date: Mon Jan 29 11:08:59 2018 +0200 loplugin:useuniqueptr in SvxRTFItemStackType Change-Id: I1677915d91fb151997d4bef18473f33ab2f09648 Reviewed-on: https://gerrit.libreoffice.org/49173 Tested-by: Jenkins <[email protected]> Reviewed-by: Noel Grandin <[email protected]> diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index 3e2b8da1fd6e..b9d6dd33a887 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -945,9 +945,9 @@ SvxRTFItemStackType::SvxRTFItemStackType( , m_pChildList( nullptr ) , nStyleNo( 0 ) { - pSttNd = rPos.MakeNodeIdx(); + pSttNd.reset( rPos.MakeNodeIdx() ); nSttCnt = rPos.GetCntIdx(); - pEndNd = pSttNd; + pEndNd = pSttNd.get(); nEndCnt = nSttCnt; } @@ -959,9 +959,9 @@ SvxRTFItemStackType::SvxRTFItemStackType( , m_pChildList( nullptr ) , nStyleNo( rCpy.nStyleNo ) { - pSttNd = rPos.MakeNodeIdx(); + pSttNd.reset( rPos.MakeNodeIdx() ); nSttCnt = rPos.GetCntIdx(); - pEndNd = pSttNd; + pEndNd = pSttNd.get(); nEndCnt = nSttCnt; aAttrSet.SetParent( &rCpy.aAttrSet ); @@ -971,26 +971,23 @@ SvxRTFItemStackType::SvxRTFItemStackType( SvxRTFItemStackType::~SvxRTFItemStackType() { - delete m_pChildList; - if( pSttNd != pEndNd ) + if( pSttNd.get() != pEndNd ) delete pEndNd; - delete pSttNd; } void SvxRTFItemStackType::Add(std::unique_ptr<SvxRTFItemStackType> pIns) { if (!m_pChildList) - m_pChildList = new SvxRTFItemStackList; + m_pChildList.reset( new SvxRTFItemStackList ); m_pChildList->push_back(std::move(pIns)); } void SvxRTFItemStackType::SetStartPos( const EditPosition& rPos ) { - if (pSttNd != pEndNd) + if (pSttNd.get() != pEndNd) delete pEndNd; - delete pSttNd; - pSttNd = rPos.MakeNodeIdx(); - pEndNd = pSttNd; + pSttNd.reset(rPos.MakeNodeIdx() ); + pEndNd = pSttNd.get(); nSttCnt = rPos.GetCntIdx(); } @@ -1074,8 +1071,7 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser ) } if (m_pChildList->empty()) { - delete m_pChildList; - m_pChildList = nullptr; + m_pChildList.reset(); } } void SvxRTFItemStackType::SetRTFDefaults( const SfxItemSet& rDefaults ) diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx index abba52d1c214..73e885553a43 100644 --- a/include/editeng/svxrtf.hxx +++ b/include/editeng/svxrtf.hxx @@ -312,9 +312,10 @@ class EDITENG_DLLPUBLIC SvxRTFItemStackType friend class SvxRTFParser; SfxItemSet aAttrSet; - EditNodeIdx *pSttNd, *pEndNd; + std::unique_ptr<EditNodeIdx> pSttNd; + EditNodeIdx *pEndNd; sal_Int32 nSttCnt, nEndCnt; - SvxRTFItemStackList* m_pChildList; + std::unique_ptr<SvxRTFItemStackList> m_pChildList; sal_uInt16 nStyleNo; SvxRTFItemStackType(SvxRTFItemStackType const&) = delete; commit 76643b208c7f0c43b0603e08a3b37f29878c42ea Author: Noel Grandin <[email protected]> Date: Mon Jan 29 11:06:29 2018 +0200 loplugin:useuniqueptr in SvxNumRule Change-Id: I778f62edbddfa2ca10eefa396272e7b011025513 Reviewed-on: https://gerrit.libreoffice.org/49172 Tested-by: Jenkins <[email protected]> Reviewed-by: Noel Grandin <[email protected]> diff --git a/editeng/source/items/numitem.cxx b/editeng/source/items/numitem.cxx index c7b06b773e78..3e5fc65907ea 100644 --- a/editeng/source/items/numitem.cxx +++ b/editeng/source/items/numitem.cxx @@ -559,7 +559,7 @@ SvxNumRule::SvxNumRule( SvxNumRuleFlags nFeatures, { if(i < nLevels) { - aFmts[i] = new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER); + aFmts[i].reset( new SvxNumberFormat(SVX_NUM_CHARS_UPPER_LETTER) ); // It is a distinction between writer and draw if(nFeatures & SvxNumRuleFlags::CONTINUOUS) { @@ -607,9 +607,9 @@ SvxNumRule::SvxNumRule(const SvxNumRule& rCopy) for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) { if(rCopy.aFmts[i]) - aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]); + aFmts[i].reset( new SvxNumberFormat(*rCopy.aFmts[i]) ); else - aFmts[i] = nullptr; + aFmts[i].reset(); aFmtsSet[i] = rCopy.aFmtsSet[i]; } } @@ -632,11 +632,11 @@ SvxNumRule::SvxNumRule( SvStream &rStream ) bool hasNumberingFormat = nTmp16 & 1; aFmtsSet[i] = nTmp16 & 2; // fdo#68648 reset flag if ( hasNumberingFormat ){ - aFmts[i] = new SvxNumberFormat( rStream ); + aFmts[i].reset( new SvxNumberFormat( rStream ) ); } else { - aFmts[i] = nullptr; + aFmts[i].reset(); aFmtsSet[i] = false; // actually only false is valid } } @@ -690,7 +690,7 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const { xmlTextWriterStartElement(pWriter, BAD_CAST("aFmts")); xmlTextWriterWriteAttribute(pWriter, BAD_CAST("i"), BAD_CAST(OUString::number(i).getStr())); - xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", aFmts[i]); + xmlTextWriterWriteFormatAttribute(pWriter, BAD_CAST("ptr"), "%p", aFmts[i].get()); xmlTextWriterEndElement(pWriter); } } @@ -700,8 +700,6 @@ void SvxNumRule::dumpAsXml(struct _xmlTextWriter* pWriter) const SvxNumRule::~SvxNumRule() { - for(SvxNumberFormat* aFmt : aFmts) - delete aFmt; if(!--nRefCount) { DELETEZ(pStdNumFmt); @@ -717,11 +715,10 @@ SvxNumRule& SvxNumRule::operator=( const SvxNumRule& rCopy ) eNumberingType = rCopy.eNumberingType; for(sal_uInt16 i = 0; i < SVX_MAX_NUM; i++) { - delete aFmts[i]; if(rCopy.aFmts[i]) - aFmts[i] = new SvxNumberFormat(*rCopy.aFmts[i]); + aFmts[i].reset( new SvxNumberFormat(*rCopy.aFmts[i]) ); else - aFmts[i] = nullptr; + aFmts[i].reset(); aFmtsSet[i] = rCopy.aFmtsSet[i]; } return *this; @@ -753,7 +750,7 @@ const SvxNumberFormat* SvxNumRule::Get(sal_uInt16 nLevel)const { DBG_ASSERT(nLevel < SVX_MAX_NUM, "Wrong Level" ); if( nLevel < SVX_MAX_NUM ) - return aFmtsSet[nLevel] ? aFmts[nLevel] : nullptr; + return aFmtsSet[nLevel] ? aFmts[nLevel].get() : nullptr; else return nullptr; } @@ -788,8 +785,7 @@ void SvxNumRule::SetLevel( sal_uInt16 i, const SvxNumberFormat& rNumFmt, bool bI if (bReplace) { - delete aFmts[i]; - aFmts[i] = new SvxNumberFormat(rNumFmt); + aFmts[i].reset( new SvxNumberFormat(rNumFmt) ); aFmtsSet[i] = bIsValid; } } @@ -806,8 +802,7 @@ void SvxNumRule::SetLevel(sal_uInt16 nLevel, const SvxNumberFormat* pFmt) SetLevel(nLevel, *pFmt); else { - delete aFmts[nLevel]; - aFmts[nLevel] = nullptr; + aFmts[nLevel].reset(); } } } diff --git a/include/editeng/numitem.hxx b/include/editeng/numitem.hxx index 1acc63f6431c..f6fb25eb8476 100644 --- a/include/editeng/numitem.hxx +++ b/include/editeng/numitem.hxx @@ -245,7 +245,7 @@ class EDITENG_DLLPUBLIC SvxNumRule final SvxNumRuleType eNumberingType; // Type of numbering bool bContinuousNumbering; // sequential numbering - SvxNumberFormat* aFmts[SVX_MAX_NUM]; + std::unique_ptr<SvxNumberFormat> aFmts[SVX_MAX_NUM]; bool aFmtsSet[SVX_MAX_NUM]; // Flags indicating valid levels static sal_Int32 nRefCount; _______________________________________________ Libreoffice-commits mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
