sw/inc/expfld.hxx | 16 +++++----------- sw/source/core/edit/edattr.cxx | 7 +++---- sw/source/core/fields/expfld.cxx | 16 ++++++++-------- sw/source/ui/fldui/fldref.cxx | 36 ++++++++++++++++++------------------ 4 files changed, 34 insertions(+), 41 deletions(-)
New commits: commit 9743bec6d81b19d38b69d8a52d969e90c6aef1b5 Author: Noel Grandin <noel.gran...@collabora.co.uk> AuthorDate: Tue Oct 2 10:40:01 2018 +0200 Commit: Noel Grandin <noel.gran...@collabora.co.uk> CommitDate: Thu Oct 4 11:41:17 2018 +0200 loplugin:useuniqueptr in SwSeqFieldList no need to store such a small structure separately on the heap Change-Id: I36b3ad5250718b7bdf526f5f67219740c69a549a Reviewed-on: https://gerrit.libreoffice.org/61298 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk> diff --git a/sw/inc/expfld.hxx b/sw/inc/expfld.hxx index 025ff802190f..7389a6d40ec9 100644 --- a/sw/inc/expfld.hxx +++ b/sw/inc/expfld.hxx @@ -45,7 +45,7 @@ OUString ReplacePoint(const OUString& sTmpName, bool bWithCommandType = false); struct SeqFieldLstElem { OUString sDlgEntry; - sal_uInt16 const nSeqNo; + sal_uInt16 nSeqNo; SeqFieldLstElem( const OUString& rStr, sal_uInt16 nNo ) : sDlgEntry( rStr ), nSeqNo( nNo ) @@ -54,20 +54,14 @@ struct SeqFieldLstElem class SW_DLLPUBLIC SwSeqFieldList { - std::vector<SeqFieldLstElem*> maData; + std::vector<SeqFieldLstElem> maData; public: - ~SwSeqFieldList() - { - for( std::vector<SeqFieldLstElem*>::const_iterator it = maData.begin(); it != maData.end(); ++it ) - delete *it; - } - - bool InsertSort(SeqFieldLstElem* pNew); + bool InsertSort(SeqFieldLstElem aNew); bool SeekEntry(const SeqFieldLstElem& rNew, size_t* pPos) const; size_t Count() { return maData.size(); } - SeqFieldLstElem* operator[](size_t nIndex) { return maData[nIndex]; } - const SeqFieldLstElem* operator[](size_t nIndex) const { return maData[nIndex]; } + SeqFieldLstElem& operator[](size_t nIndex) { return maData[nIndex]; } + const SeqFieldLstElem& operator[](size_t nIndex) const { return maData[nIndex]; } void Clear() { maData.clear(); } }; diff --git a/sw/source/core/edit/edattr.cxx b/sw/source/core/edit/edattr.cxx index 5837e76c7c7b..6d9bcab5fcc8 100644 --- a/sw/source/core/edit/edattr.cxx +++ b/sw/source/core/edit/edattr.cxx @@ -468,10 +468,9 @@ size_t SwEditShell::GetSeqFootnoteList( SwSeqFieldList& rList, bool bEndNotes ) sText += " "; sText += pTextNd->GetExpandText(); - SeqFieldLstElem* pNew = new SeqFieldLstElem( sText, - pTextFootnote->GetSeqRefNo() ); - while( rList.InsertSort( pNew ) ) - pNew->sDlgEntry += " "; + SeqFieldLstElem aNew( sText, pTextFootnote->GetSeqRefNo() ); + while( rList.InsertSort( aNew ) ) + aNew.sDlgEntry += " "; } } } diff --git a/sw/source/core/fields/expfld.cxx b/sw/source/core/fields/expfld.cxx index ec9318e82134..97c415050724 100644 --- a/sw/source/core/fields/expfld.cxx +++ b/sw/source/core/fields/expfld.cxx @@ -595,10 +595,10 @@ size_t SwSetExpFieldType::GetSeqFieldList( SwSeqFieldList& rList ) nullptr != ( pNd = pF->GetTextField()->GetpTextNode() ) && pNd->GetNodes().IsDocNodes() ) { - SeqFieldLstElem* pNew = new SeqFieldLstElem( + SeqFieldLstElem aNew( pNd->GetExpandText(), static_cast<SwSetExpField*>(pF->GetField())->GetSeqNumber() ); - rList.InsertSort( pNew ); + rList.InsertSort( aNew ); } } @@ -693,9 +693,9 @@ void SwSetExpFieldType::PutValue( const uno::Any& rAny, sal_uInt16 nWhichId ) } } -bool SwSeqFieldList::InsertSort( SeqFieldLstElem* pNew ) +bool SwSeqFieldList::InsertSort( SeqFieldLstElem aNew ) { - OUStringBuffer aBuf(pNew->sDlgEntry); + OUStringBuffer aBuf(aNew.sDlgEntry); const sal_Int32 nLen = aBuf.getLength(); for (sal_Int32 i = 0; i < nLen; ++i) { @@ -704,12 +704,12 @@ bool SwSeqFieldList::InsertSort( SeqFieldLstElem* pNew ) aBuf[i]=' '; } } - pNew->sDlgEntry = aBuf.makeStringAndClear(); + aNew.sDlgEntry = aBuf.makeStringAndClear(); size_t nPos = 0; - bool bRet = SeekEntry( *pNew, &nPos ); + bool bRet = SeekEntry( aNew, &nPos ); if( !bRet ) - maData.insert( maData.begin() + nPos, pNew ); + maData.insert( maData.begin() + nPos, aNew ); return bRet; } @@ -736,7 +736,7 @@ bool SwSeqFieldList::SeekEntry( const SeqFieldLstElem& rNew, size_t* pP ) const const size_t nM = nU + ( nO - nU ) / 2; //#59900# Sorting should sort number correctly (e.g. "10" after "9" not after "1") - const OUString rTmp1 = maData[nM]->sDlgEntry; + const OUString rTmp1 = maData[nM].sDlgEntry; sal_Int32 nFndPos1 = 0; const OUString sNum1( rTmp1.getToken( 0, ' ', nFndPos1 )); sal_Int32 nCmp; diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx index 10ace845154d..c9b0063d86d3 100644 --- a/sw/source/ui/fldui/fldref.cxx +++ b/sw/source/ui/fldui/fldref.cxx @@ -555,13 +555,13 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString) for( size_t n = 0; n < nCnt; ++n ) { - bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString); if(isSubstring) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + m_pSelectionLB->InsertEntry( aArr[ n ].sDlgEntry ); } - if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ]->nSeqNo) - sOldSel = aArr[n]->sDlgEntry; + if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ].nSeqNo) + sOldSel = aArr[n].sDlgEntry; } } else if (nTypeId == REFFLDFLAG_ENDNOTE) @@ -572,13 +572,13 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString) for( size_t n = 0; n < nCnt; ++n ) { - bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString); if(isSubstring) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + m_pSelectionLB->InsertEntry( aArr[ n ].sDlgEntry ); } - if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ]->nSeqNo) - sOldSel = aArr[n]->sDlgEntry; + if (IsFieldEdit() && pRefField->GetSeqNo() == aArr[ n ].nSeqNo) + sOldSel = aArr[n].sDlgEntry; } } // #i83479# @@ -661,14 +661,14 @@ void SwFieldRefPage::UpdateSubType(const OUString& filterString) const size_t nCnt = pType->GetSeqFieldList( aArr ); for( size_t n = 0; n < nCnt; ++n ) { - bool isSubstring = MatchSubstring(aArr[ n ]->sDlgEntry, filterString); + bool isSubstring = MatchSubstring(aArr[ n ].sDlgEntry, filterString); if(isSubstring) { - m_pSelectionLB->InsertEntry( aArr[ n ]->sDlgEntry ); + m_pSelectionLB->InsertEntry( aArr[ n ].sDlgEntry ); } if (IsFieldEdit() && sOldSel.isEmpty() && - aArr[ n ]->nSeqNo == pRefField->GetSeqNo()) - sOldSel = aArr[ n ]->sDlgEntry; + aArr[ n ].nSeqNo == pRefField->GetSeqNo()) + sOldSel = aArr[ n ].sDlgEntry; } if (IsFieldEdit() && sOldSel.isEmpty()) @@ -988,9 +988,9 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* ) if (pSh->GetSeqFootnoteList(aArr) && aArr.SeekEntry(aElem, &nPos)) { - aVal = OUString::number( aArr[nPos]->nSeqNo ); + aVal = OUString::number( aArr[nPos].nSeqNo ); - if (IsFieldEdit() && aArr[nPos]->nSeqNo == pRefField->GetSeqNo()) + if (IsFieldEdit() && aArr[nPos].nSeqNo == pRefField->GetSeqNo()) bModified = true; // can happen with fields of which the references were deleted } else if (IsFieldEdit()) @@ -1009,9 +1009,9 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* ) if (pSh->GetSeqFootnoteList(aArr, true) && aArr.SeekEntry(aElem, &nPos)) { - aVal = OUString::number( aArr[nPos]->nSeqNo ); + aVal = OUString::number( aArr[nPos].nSeqNo ); - if (IsFieldEdit() && aArr[nPos]->nSeqNo == pRefField->GetSeqNo()) + if (IsFieldEdit() && aArr[nPos].nSeqNo == pRefField->GetSeqNo()) bModified = true; // can happen with fields of which the reference was deleted } else if (IsFieldEdit()) @@ -1078,9 +1078,9 @@ bool SwFieldRefPage::FillItemSet(SfxItemSet* ) if (pType->GetSeqFieldList(aArr) && aArr.SeekEntry(aElem, &nPos)) { - aVal = OUString::number( aArr[nPos]->nSeqNo ); + aVal = OUString::number( aArr[nPos].nSeqNo ); - if (IsFieldEdit() && aArr[nPos]->nSeqNo == pRefField->GetSeqNo()) + if (IsFieldEdit() && aArr[nPos].nSeqNo == pRefField->GetSeqNo()) bModified = true; // can happen with fields of which the reference was deleted } else if (IsFieldEdit()) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits