[Libreoffice-commits] core.git: editeng/source include/editeng

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Mon May 31 16:33:53 UTC 2021


 editeng/source/editeng/eertfpar.cxx |    8 +++---
 editeng/source/editeng/eertfpar.hxx |    2 -
 editeng/source/rtf/rtfitem.cxx      |    2 -
 editeng/source/rtf/svxrtf.cxx       |   42 ++++++++++++++++--------------------
 include/editeng/svxrtf.hxx          |   12 +++++-----
 5 files changed, 31 insertions(+), 35 deletions(-)

New commits:
commit 2efe1e8977a83143696b8db49c7c26bbff91c04c
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon May 31 10:10:50 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 31 18:33:10 2021 +0200

    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 at collabora.co.uk>

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
diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx
index 42198a7acb72..87283eadf11d 100644
--- a/include/editeng/svxrtf.hxx
+++ b/include/editeng/svxrtf.hxx
@@ -69,7 +69,7 @@ public:
     sal_Int32   GetCntIdx() const;
 
     // clone NodeIndex
-    std::unique_ptr<EditNodeIdx> MakeNodeIdx() const;
+    EditNodeIdx MakeNodeIdx() const;
 };
 
 typedef std::map<short, vcl::Font> SvxRTFFontTbl;
@@ -238,7 +238,7 @@ protected:
 
     virtual void InsertText() = 0;
     virtual void MovePos( bool bForward = true ) = 0;
-    virtual void SetEndPrevPara( EditNodeIdx*& rpNodePos,
+    virtual void SetEndPrevPara( std::optional<EditNodeIdx>& rpNodePos,
                                  sal_Int32& rCntPos )=0;
     virtual void SetAttrInDoc( SvxRTFItemStackType &rSet );
     // for Tokens, which are not evaluated in ReadAttr
@@ -293,8 +293,8 @@ class SvxRTFItemStackType
     friend class SvxRTFParser;
 
     SfxItemSet   aAttrSet;
-    std::unique_ptr<EditNodeIdx> pSttNd;
-    EditNodeIdx  *pEndNd;
+    std::optional<EditNodeIdx>  mxStartNodeIdx;
+    std::optional<EditNodeIdx>  mxEndNodeIdx;
     sal_Int32    nSttCnt, nEndCnt;
     std::unique_ptr<SvxRTFItemStackList> m_pChildList;
     sal_uInt16   nStyleNo;
@@ -318,8 +318,8 @@ public:
     //bad, consider this deprecated.
     void SetStartPos( const EditPosition& rPos );
 
-    const EditNodeIdx& GetSttNode() const { return *pSttNd; }
-    const EditNodeIdx& GetEndNode() const { return *pEndNd; }
+    const EditNodeIdx& GetSttNode() const { return *mxStartNodeIdx; }
+    const EditNodeIdx& GetEndNode() const { return *mxEndNodeIdx; }
 
     sal_Int32 GetSttCnt() const { return nSttCnt; }
     sal_Int32 GetEndCnt() const { return nEndCnt; }


More information about the Libreoffice-commits mailing list