diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-31 10:10:50 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2021-05-31 18:33:10 +0200 |
commit | 2efe1e8977a83143696b8db49c7c26bbff91c04c (patch) | |
tree | 69f20a1a8adfb495350c78de50d6f01923a32c77 /editeng | |
parent | 21ad3e6cbdf9568c1152a2eab8178e4219e40c33 (diff) |
no need to allocate EditNodeIdx separately
it is just two pointers
Change-Id: I80a9206b9f94fb4a4401352b93fcd727f787f52d
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116474
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'editeng')
-rw-r--r-- | editeng/source/editeng/eertfpar.cxx | 8 | ||||
-rw-r--r-- | editeng/source/editeng/eertfpar.hxx | 2 | ||||
-rw-r--r-- | editeng/source/rtf/rtfitem.cxx | 2 | ||||
-rw-r--r-- | editeng/source/rtf/svxrtf.cxx | 42 |
4 files changed, 25 insertions, 29 deletions
diff --git a/editeng/source/editeng/eertfpar.cxx b/editeng/source/editeng/eertfpar.cxx index ecc1247c913d..278699dbfcb1 100644 --- a/editeng/source/editeng/eertfpar.cxx +++ b/editeng/source/editeng/eertfpar.cxx @@ -275,7 +275,7 @@ void EditRTFParser::MovePos( bool const bForward ) aCurSel.Max(), i18n::CharacterIteratorMode::SKIPCHARACTER); } -void EditRTFParser::SetEndPrevPara( EditNodeIdx*& rpNodePos, +void EditRTFParser::SetEndPrevPara( std::optional<EditNodeIdx>& rpNodePos, sal_Int32& rCntPos ) { // The Intention is to: determine the current insert position of the @@ -289,7 +289,7 @@ void EditRTFParser::SetEndPrevPara( EditNodeIdx*& rpNodePos, nCurPara--; ContentNode* pPrevNode = mpEditEngine->GetEditDoc().GetObject( nCurPara ); assert(pPrevNode && "pPrevNode = 0!"); - rpNodePos = new EditNodeIdx(mpEditEngine, pPrevNode); + rpNodePos = EditNodeIdx(mpEditEngine, pPrevNode); rCntPos = pPrevNode->Len(); } @@ -612,9 +612,9 @@ sal_Int32 EditNodeIdx::GetIdx() const EditPosition::EditPosition(EditEngine* pEE, EditSelection* pSel) : mpEditEngine(pEE), mpCurSel(pSel) {} -std::unique_ptr<EditNodeIdx> EditPosition::MakeNodeIdx() const +EditNodeIdx EditPosition::MakeNodeIdx() const { - return std::make_unique<EditNodeIdx>(mpEditEngine, mpCurSel->Max().GetNode()); + return EditNodeIdx(mpEditEngine, mpCurSel->Max().GetNode()); } sal_Int32 EditPosition::GetNodeIdx() const diff --git a/editeng/source/editeng/eertfpar.hxx b/editeng/source/editeng/eertfpar.hxx index 582e46a68a81..19ce00ce3297 100644 --- a/editeng/source/editeng/eertfpar.hxx +++ b/editeng/source/editeng/eertfpar.hxx @@ -37,7 +37,7 @@ private: virtual void InsertPara() override; virtual void InsertText() override; virtual void MovePos( bool bForward = true ) override; - virtual void SetEndPrevPara( EditNodeIdx*& rpNodePos, + virtual void SetEndPrevPara( std::optional<EditNodeIdx>& rpNodePos, sal_Int32& rCntPos ) override; virtual void UnknownAttrToken( int nToken ) override; diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx index 699fe0834f7e..ef370d98995f 100644 --- a/editeng/source/rtf/rtfitem.cxx +++ b/editeng/source/rtf/rtfitem.cxx @@ -206,7 +206,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet ) break; SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); - if( !pCurrent || (pCurrent->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() && + if( !pCurrent || (pCurrent->mxStartNodeIdx->GetIdx() == mxInsertPosition->GetNodeIdx() && pCurrent->nSttCnt == mxInsertPosition->GetCntIdx() )) break; diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx index df0f030f0c57..ac262af2e759 100644 --- a/editeng/source/rtf/svxrtf.cxx +++ b/editeng/source/rtf/svxrtf.cxx @@ -680,7 +680,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack SvxRTFItemStackType *pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); do { // middle check loop - sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx(); + sal_Int32 nOldSttNdIdx = pOld->mxStartNodeIdx->GetIdx(); if (!pOld->m_pChildList && ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) || (nOldSttNdIdx == mxInsertPosition->GetNodeIdx() && @@ -718,8 +718,8 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack bCrsrBack = nNd != mxInsertPosition->GetNodeIdx(); } - if( pOld->pSttNd->GetIdx() < mxInsertPosition->GetNodeIdx() || - ( pOld->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() && + if( pOld->mxStartNodeIdx->GetIdx() < mxInsertPosition->GetNodeIdx() || + ( pOld->mxStartNodeIdx->GetIdx() == mxInsertPosition->GetNodeIdx() && pOld->nSttCnt <= mxInsertPosition->GetCntIdx() ) ) { if( !bCrsrBack ) @@ -756,7 +756,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack pNew->nStyleNo = 0; // Now span the real area of pNew from old - SetEndPrevPara( pOld->pEndNd, pOld->nEndCnt ); + SetEndPrevPara( pOld->mxEndNodeIdx, pOld->nEndCnt ); pNew->nSttCnt = 0; if( IsChkStyleAttr() ) @@ -783,7 +783,7 @@ void SvxRTFParser::AttrGroupEnd() // process the current, delete from Stack } } - pOld->pEndNd = mxInsertPosition->MakeNodeIdx().release(); + pOld->mxEndNodeIdx = mxInsertPosition->MakeNodeIdx(); pOld->nEndCnt = mxInsertPosition->GetCntIdx(); /* @@ -874,7 +874,7 @@ void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet ) bool SvxRTFParser::IsAttrSttPos() { SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get(); - return !pCurrent || (pCurrent->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() && + return !pCurrent || (pCurrent->mxStartNodeIdx->GetIdx() == mxInsertPosition->GetNodeIdx() && pCurrent->nSttCnt == mxInsertPosition->GetCntIdx()); } @@ -928,9 +928,9 @@ SvxRTFItemStackType::SvxRTFItemStackType( : aAttrSet( rPool, pWhichRange ) , nStyleNo( 0 ) { - pSttNd = rPos.MakeNodeIdx(); + mxStartNodeIdx = rPos.MakeNodeIdx(); nSttCnt = rPos.GetCntIdx(); - pEndNd = pSttNd.get(); + mxEndNodeIdx = mxStartNodeIdx; nEndCnt = nSttCnt; } @@ -941,9 +941,9 @@ SvxRTFItemStackType::SvxRTFItemStackType( : aAttrSet( *rCpy.aAttrSet.GetPool(), rCpy.aAttrSet.GetRanges() ) , nStyleNo( rCpy.nStyleNo ) { - pSttNd = rPos.MakeNodeIdx(); + mxStartNodeIdx = rPos.MakeNodeIdx(); nSttCnt = rPos.GetCntIdx(); - pEndNd = pSttNd.get(); + mxEndNodeIdx = mxStartNodeIdx; nEndCnt = nSttCnt; aAttrSet.SetParent( &rCpy.aAttrSet ); @@ -991,8 +991,6 @@ void SvxRTFItemStackType::DropChildList() SvxRTFItemStackType::~SvxRTFItemStackType() { - if( pSttNd.get() != pEndNd ) - delete pEndNd; } void SvxRTFItemStackType::Add(std::unique_ptr<SvxRTFItemStackType> pIns) @@ -1004,10 +1002,8 @@ void SvxRTFItemStackType::Add(std::unique_ptr<SvxRTFItemStackType> pIns) void SvxRTFItemStackType::SetStartPos( const EditPosition& rPos ) { - if (pSttNd.get() != pEndNd) - delete pEndNd; - pSttNd = rPos.MakeNodeIdx(); - pEndNd = pSttNd.get(); + mxStartNodeIdx = rPos.MakeNodeIdx(); + mxEndNodeIdx = mxStartNodeIdx; nSttCnt = rPos.GetCntIdx(); } @@ -1019,11 +1015,11 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser ) SvxRTFItemStackType* pTmp = (*m_pChildList)[0].get(); if( !pTmp->aAttrSet.Count() || - pSttNd->GetIdx() != pTmp->pSttNd->GetIdx() || + mxStartNodeIdx->GetIdx() != pTmp->mxStartNodeIdx->GetIdx() || nSttCnt != pTmp->nSttCnt ) return; - EditNodeIdx* pLastNd = pTmp->pEndNd; + EditNodeIdx aLastNd = *pTmp->mxEndNodeIdx; sal_Int32 nLastCnt = pTmp->nEndCnt; SfxItemSet aMrgSet( pTmp->aAttrSet ); @@ -1034,10 +1030,10 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser ) pTmp->Compress( rParser ); if( !pTmp->nSttCnt - ? (pLastNd->GetIdx()+1 != pTmp->pSttNd->GetIdx() || - !rParser.IsEndPara( pLastNd, nLastCnt ) ) + ? (aLastNd.GetIdx()+1 != pTmp->mxStartNodeIdx->GetIdx() || + !rParser.IsEndPara( &aLastNd, nLastCnt ) ) : ( pTmp->nSttCnt != nLastCnt || - pLastNd->GetIdx() != pTmp->pSttNd->GetIdx() )) + aLastNd.GetIdx() != pTmp->mxStartNodeIdx->GetIdx() )) { while (++n < m_pChildList->size()) { @@ -1067,11 +1063,11 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser ) return; } - pLastNd = pTmp->pEndNd; + aLastNd = *pTmp->mxEndNodeIdx; nLastCnt = pTmp->nEndCnt; } - if( pEndNd->GetIdx() != pLastNd->GetIdx() || nEndCnt != nLastCnt ) + if( mxEndNodeIdx->GetIdx() != aLastNd.GetIdx() || nEndCnt != nLastCnt ) return; // It can be merged |