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

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


 editeng/source/editeng/eertfpar.cxx |    5 ----
 editeng/source/rtf/rtfitem.cxx      |   12 +++++-----
 editeng/source/rtf/svxrtf.cxx       |   40 ++++++++++++++++++------------------
 include/editeng/svxrtf.hxx          |    6 +----
 4 files changed, 28 insertions(+), 35 deletions(-)

New commits:
commit 21ad3e6cbdf9568c1152a2eab8178e4219e40c33
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Mon May 31 09:49:55 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Mon May 31 18:32:39 2021 +0200

    EditPosition does not need to be allocated separately
    
    it's just two pointers big
    
    Change-Id: Ie2d71f4530fa92a3d125446a6c45035e88617b97
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116473
    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 2be675266f36..ecc1247c913d 100644
--- a/editeng/source/editeng/eertfpar.cxx
+++ b/editeng/source/editeng/eertfpar.cxx
@@ -612,11 +612,6 @@ sal_Int32 EditNodeIdx::GetIdx() const
 EditPosition::EditPosition(EditEngine* pEE, EditSelection* pSel) :
     mpEditEngine(pEE), mpCurSel(pSel) {}
 
-std::unique_ptr<EditPosition> EditPosition::Clone() const
-{
-    return std::unique_ptr<EditPosition>(new EditPosition(mpEditEngine, mpCurSel));
-}
-
 std::unique_ptr<EditNodeIdx> EditPosition::MakeNodeIdx() const
 {
     return std::make_unique<EditNodeIdx>(mpEditEngine, mpCurSel->Max().GetNode());
diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx
index de9a66d8eddc..699fe0834f7e 100644
--- a/editeng/source/rtf/rtfitem.cxx
+++ b/editeng/source/rtf/rtfitem.cxx
@@ -206,8 +206,8 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
                     break;
 
                 SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
-                if( !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
-                    pCurrent->nSttCnt == pInsPos->GetCntIdx() ))
+                if( !pCurrent || (pCurrent->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() &&
+                    pCurrent->nSttCnt == mxInsertPosition->GetCntIdx() ))
                     break;
 
                 int nLastToken = GetStackPtr(-1)->nTokenId;
@@ -219,7 +219,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
                 {
                     // Open a new Group
                     std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
-                                                *pCurrent, *pInsPos, true ));
+                                                *pCurrent, *mxInsertPosition, true ));
                     pNew->SetRTFDefaults( GetRTFDefaults() );
 
                     // "Set" all valid attributes up until this point
@@ -232,7 +232,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
                 }
                 else
                     // continue to use this entry as a new one
-                    pCurrent->SetStartPos( *pInsPos );
+                    pCurrent->SetStartPos( *mxInsertPosition );
 
                 pSet = &pCurrent->aAttrSet;
             } while( false );
@@ -1704,7 +1704,7 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
         if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo)
         {
             // open a new group
-            std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *pInsPos, true ));
+            std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType( *pCurrent, *mxInsertPosition, true ));
             pNew->SetRTFDefaults( GetRTFDefaults() );
 
             // Set all until here valid attributes
@@ -1717,7 +1717,7 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
         else
         {
             // continue to use this entry as new
-            pCurrent->SetStartPos( *pInsPos );
+            pCurrent->SetStartPos( *mxInsertPosition );
             bNewStkEntry = false;
         }
     }
diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
index 4bf5c3811bdc..df0f030f0c57 100644
--- a/editeng/source/rtf/svxrtf.cxx
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -83,14 +83,14 @@ SvxRTFParser::~SvxRTFParser()
 
 void SvxRTFParser::SetInsPos( const EditPosition& rNew )
 {
-    pInsPos = rNew.Clone();
+    mxInsertPosition = rNew;
 }
 
 SvParserState SvxRTFParser::CallParser()
 {
-    DBG_ASSERT( pInsPos, "no insertion position");
+    DBG_ASSERT( mxInsertPosition, "no insertion position");
 
-    if( !pInsPos )
+    if( !mxInsertPosition )
         return SvParserState::Error;
 
     if( !maColorTable.empty() )
@@ -614,10 +614,10 @@ SvxRTFItemStackType* SvxRTFParser::GetAttrSet_()
     SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
     std::unique_ptr<SvxRTFItemStackType> pNew;
     if( pCurrent )
-        pNew.reset(new SvxRTFItemStackType( *pCurrent, *pInsPos, false/*bCopyAttr*/ ));
+        pNew.reset(new SvxRTFItemStackType( *pCurrent, *mxInsertPosition, false/*bCopyAttr*/ ));
     else
         pNew.reset(new SvxRTFItemStackType( *pAttrPool, aWhichMap.data(),
-                                        *pInsPos ));
+                                        *mxInsertPosition ));
     pNew->SetRTFDefaults( GetRTFDefaults() );
 
     aAttrStack.push_back( std::move(pNew) );
@@ -683,8 +683,8 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
         sal_Int32 nOldSttNdIdx = pOld->pSttNd->GetIdx();
         if (!pOld->m_pChildList &&
             ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
-            (nOldSttNdIdx == pInsPos->GetNodeIdx() &&
-            pOld->nSttCnt == pInsPos->GetCntIdx() )))
+            (nOldSttNdIdx == mxInsertPosition->GetNodeIdx() &&
+            pOld->nSttCnt == mxInsertPosition->GetCntIdx() )))
             break;          // no attributes or Area
 
         // set only the attributes that are different from the parent
@@ -708,25 +708,25 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
         }
 
         // Set all attributes which have been defined from start until here
-        bool bCrsrBack = !pInsPos->GetCntIdx();
+        bool bCrsrBack = !mxInsertPosition->GetCntIdx();
         if( bCrsrBack )
         {
             // at the beginning of a paragraph? Move back one position
-            sal_Int32 nNd = pInsPos->GetNodeIdx();
+            sal_Int32 nNd = mxInsertPosition->GetNodeIdx();
             MovePos(false);
             // if can not move backward then later don't move forward !
-            bCrsrBack = nNd != pInsPos->GetNodeIdx();
+            bCrsrBack = nNd != mxInsertPosition->GetNodeIdx();
         }
 
-        if( pOld->pSttNd->GetIdx() < pInsPos->GetNodeIdx() ||
-            ( pOld->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
-              pOld->nSttCnt <= pInsPos->GetCntIdx() ) )
+        if( pOld->pSttNd->GetIdx() < mxInsertPosition->GetNodeIdx() ||
+            ( pOld->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() &&
+              pOld->nSttCnt <= mxInsertPosition->GetCntIdx() ) )
         {
             if( !bCrsrBack )
             {
                 // all pard attributes are only valid until the previous
                 // paragraph !!
-                if( nOldSttNdIdx == pInsPos->GetNodeIdx() )
+                if( nOldSttNdIdx == mxInsertPosition->GetNodeIdx() )
                 {
                 }
                 else
@@ -736,7 +736,7 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
                     // - all paragraph attributes to get the area
                     //   up to the previous paragraph
                     std::unique_ptr<SvxRTFItemStackType> pNew(
-                        new SvxRTFItemStackType(*pOld, *pInsPos, true));
+                        new SvxRTFItemStackType(*pOld, *mxInsertPosition, true));
                     pNew->aAttrSet.SetParent( pOld->aAttrSet.GetParent() );
 
                     // Delete all paragraph attributes from pNew
@@ -783,8 +783,8 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
                 }
             }
 
-            pOld->pEndNd = pInsPos->MakeNodeIdx().release();
-            pOld->nEndCnt = pInsPos->GetCntIdx();
+            pOld->pEndNd = mxInsertPosition->MakeNodeIdx().release();
+            pOld->nEndCnt = mxInsertPosition->GetCntIdx();
 
             /*
             #i21422#
@@ -812,7 +812,7 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
 
                     // Open a new Group.
                     std::unique_ptr<SvxRTFItemStackType> pNew(new SvxRTFItemStackType(
-                                            *pCurrent, *pInsPos, true ));
+                                            *pCurrent, *mxInsertPosition, true ));
                     pNew->SetRTFDefaults( GetRTFDefaults() );
 
                     // Set all until here valid Attributes
@@ -874,8 +874,8 @@ void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet )
 bool SvxRTFParser::IsAttrSttPos()
 {
     SvxRTFItemStackType* pCurrent = aAttrStack.empty() ? nullptr : aAttrStack.back().get();
-    return !pCurrent || (pCurrent->pSttNd->GetIdx() == pInsPos->GetNodeIdx() &&
-        pCurrent->nSttCnt == pInsPos->GetCntIdx());
+    return !pCurrent || (pCurrent->pSttNd->GetIdx() == mxInsertPosition->GetNodeIdx() &&
+        pCurrent->nSttCnt == mxInsertPosition->GetCntIdx());
 }
 
 
diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx
index a711f79fd8ed..42198a7acb72 100644
--- a/include/editeng/svxrtf.hxx
+++ b/include/editeng/svxrtf.hxx
@@ -63,13 +63,11 @@ private:
 
 public:
     EditPosition(EditEngine* pIEE, EditSelection* pSel);
+    EditPosition(const EditPosition &) = default;
 
     sal_Int32   GetNodeIdx() const;
     sal_Int32   GetCntIdx() const;
 
-    // clone
-    std::unique_ptr<EditPosition> Clone() const;
-
     // clone NodeIndex
     std::unique_ptr<EditNodeIdx> MakeNodeIdx() const;
 };
@@ -170,7 +168,7 @@ class EDITENG_DLLPUBLIC SvxRTFParser : public SvRTFParser
     RTFPardAttrMapIds aPardMap;
     std::vector<sal_uInt16> aWhichMap;
 
-    std::unique_ptr<EditPosition> pInsPos;
+    std::optional<EditPosition> mxInsertPosition;
     SfxItemPool* pAttrPool;
     std::optional<Color>  mxDefaultColor;
     std::unique_ptr<vcl::Font>   pDfltFont;


More information about the Libreoffice-commits mailing list