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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Jul 20 17:23:59 UTC 2021


 editeng/source/rtf/rtfitem.cxx |    4 +--
 editeng/source/rtf/svxrtf.cxx  |   54 +++++++++++++++++------------------------
 include/editeng/svxrtf.hxx     |    2 -
 3 files changed, 26 insertions(+), 34 deletions(-)

New commits:
commit 2ebde17fec5fa991bd211c56ca93b7e528eea5b8
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Tue Jul 20 15:11:48 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Jul 20 19:23:16 2021 +0200

    no need to allocate child array separately in SvxRTFItemStackType
    
    Change-Id: Ie40cc3b2d05bbb16a2b33a6beb4fdb804454333e
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/119250
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/editeng/source/rtf/rtfitem.cxx b/editeng/source/rtf/rtfitem.cxx
index c7ea1d3f9ba6..2f7f2fde29de 100644
--- a/editeng/source/rtf/rtfitem.cxx
+++ b/editeng/source/rtf/rtfitem.cxx
@@ -214,7 +214,7 @@ void SvxRTFParser::ReadAttr( int nToken, SfxItemSet* pSet )
                 if( RTF_PARD == nLastToken || RTF_PLAIN == nLastToken )
                     break;
 
-                if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList ||
+                if (pCurrent->aAttrSet.Count() || !pCurrent->maChildList.empty() ||
                     pCurrent->nStyleNo )
                 {
                     // Open a new Group
@@ -1670,7 +1670,7 @@ void SvxRTFParser::RTFPardPlain( bool const bPard, SfxItemSet** ppSet )
         RTF_PLAIN != nLastToken &&
         BRACELEFT != nLastToken )
     {
-        if (pCurrent->aAttrSet.Count() || pCurrent->m_pChildList || pCurrent->nStyleNo)
+        if (pCurrent->aAttrSet.Count() || !pCurrent->maChildList.empty() || pCurrent->nStyleNo)
         {
             // open a new group
             auto xNew(std::make_unique<SvxRTFItemStackType>(*pCurrent, *mxInsertPosition, true));
diff --git a/editeng/source/rtf/svxrtf.cxx b/editeng/source/rtf/svxrtf.cxx
index 7bbf46a6026c..4b0fd66bb224 100644
--- a/editeng/source/rtf/svxrtf.cxx
+++ b/editeng/source/rtf/svxrtf.cxx
@@ -694,7 +694,7 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
 
     do {        // middle check loop
         sal_Int32 nOldSttNdIdx = pOld->mxStartNodeIdx->GetIdx();
-        if (!pOld->m_pChildList &&
+        if (pOld->maChildList.empty() &&
             ((!pOld->aAttrSet.Count() && !pOld->nStyleNo ) ||
             (nOldSttNdIdx == mxInsertPosition->GetNodeIdx() &&
             pOld->nSttCnt == mxInsertPosition->GetCntIdx() )))
@@ -715,7 +715,7 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
                 pItem = aIter.NextItem();
             } while (pItem);
 
-            if (!pOld->aAttrSet.Count() && !pOld->m_pChildList &&
+            if (!pOld->aAttrSet.Count() && pOld->maChildList.empty() &&
                 !pOld->nStyleNo )
                 break;
         }
@@ -815,7 +815,7 @@ void SvxRTFParser::AttrGroupEnd()   // process the current, delete from Stack
                 pCurrent->Add(std::move(pOld));
                 // split up and create new entry, because it makes no sense
                 // to create a "so long" depend list. Bug 95010
-                if (bCrsrBack && 50 < pCurrent->m_pChildList->size())
+                if (bCrsrBack && 50 < pCurrent->maChildList.size())
                 {
                     // at the beginning of a paragraph? Move back one position
                     MovePos();
@@ -869,15 +869,14 @@ void SvxRTFParser::SetAttrSet( SvxRTFItemStackType &rSet )
     if( !bIsSetDfltTab )
         SetDefault( RTF_DEFTAB, 720 );
 
-    if (rSet.m_pChildList)
+    if (!rSet.maChildList.empty())
         rSet.Compress( *this );
     if( rSet.aAttrSet.Count() || rSet.nStyleNo )
         SetAttrInDoc( rSet );
 
     // then process all the children
-    if (rSet.m_pChildList)
-        for (size_t n = 0; n < rSet.m_pChildList->size(); ++n)
-            SetAttrSet( *(*rSet.m_pChildList)[ n ] );
+    for (size_t n = 0; n < rSet.maChildList.size(); ++n)
+        SetAttrSet( *(rSet.maChildList[ n ]) );
 }
 
 // Has no text been inserted yet? (SttPos from the top Stack entry!)
@@ -1019,7 +1018,7 @@ SvxRTFItemStackType::SvxRTFItemStackType(
 */
 void SvxRTFItemStackType::DropChildList()
 {
-    if (!m_pChildList || m_pChildList->empty())
+    if (maChildList.empty())
         return;
 
     std::vector<SvxRTFItemStackType*> bfs;
@@ -1030,9 +1029,9 @@ void SvxRTFItemStackType::DropChildList()
     {
         auto* front = aQueue.front();
         aQueue.pop();
-        if (front->m_pChildList)
+        if (!front->maChildList.empty())
         {
-            for (const auto& a : *front->m_pChildList)
+            for (const auto& a : front->maChildList)
                 aQueue.push(a.get());
             bfs.push_back(front);
         }
@@ -1041,7 +1040,7 @@ void SvxRTFItemStackType::DropChildList()
     for (auto it = bfs.rbegin(); it != bfs.rend(); ++it)
     {
         SvxRTFItemStackType* pNode = *it;
-        pNode->m_pChildList.reset();
+        pNode->maChildList.clear();
     }
 }
 
@@ -1051,9 +1050,7 @@ SvxRTFItemStackType::~SvxRTFItemStackType()
 
 void SvxRTFItemStackType::Add(std::unique_ptr<SvxRTFItemStackType> pIns)
 {
-    if (!m_pChildList)
-         m_pChildList.reset( new SvxRTFItemStackList );
-    m_pChildList->push_back(std::move(pIns));
+    maChildList.push_back(std::move(pIns));
 }
 
 void SvxRTFItemStackType::SetStartPos( const EditPosition& rPos )
@@ -1065,10 +1062,9 @@ void SvxRTFItemStackType::SetStartPos( const EditPosition& rPos )
 
 void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
 {
-    ENSURE_OR_RETURN_VOID(m_pChildList, "Compress: no ChildList" );
-    ENSURE_OR_RETURN_VOID(!m_pChildList->empty(), "Compress: ChildList empty");
+    ENSURE_OR_RETURN_VOID(!maChildList.empty(), "Compress: ChildList empty");
 
-    SvxRTFItemStackType* pTmp = (*m_pChildList)[0].get();
+    SvxRTFItemStackType* pTmp = maChildList[0].get();
 
     if( !pTmp->aAttrSet.Count() ||
         mxStartNodeIdx->GetIdx() != pTmp->mxStartNodeIdx->GetIdx() ||
@@ -1079,10 +1075,10 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
     sal_Int32 nLastCnt = pTmp->nEndCnt;
 
     SfxItemSet aMrgSet( pTmp->aAttrSet );
-    for (size_t n = 1; n < m_pChildList->size(); ++n)
+    for (size_t n = 1; n < maChildList.size(); ++n)
     {
-        pTmp = (*m_pChildList)[n].get();
-        if (pTmp->m_pChildList)
+        pTmp = maChildList[n].get();
+        if (!pTmp->maChildList.empty())
             pTmp->Compress( rParser );
 
         if( !pTmp->nSttCnt
@@ -1091,10 +1087,10 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
             : ( pTmp->nSttCnt != nLastCnt ||
                 aLastNd.GetIdx() != pTmp->mxStartNodeIdx->GetIdx() ))
         {
-            while (++n < m_pChildList->size())
+            while (++n < maChildList.size())
             {
-                pTmp = (*m_pChildList)[n].get();
-                if (pTmp->m_pChildList)
+                pTmp = maChildList[n].get();
+                if (!pTmp->maChildList.empty())
                     pTmp->Compress( rParser );
             }
             return;
@@ -1129,24 +1125,20 @@ void SvxRTFItemStackType::Compress( const SvxRTFParser& rParser )
     // It can be merged
     aAttrSet.Put( aMrgSet );
 
-    size_t n = 0, nChildLen = m_pChildList->size();
+    size_t n = 0, nChildLen = maChildList.size();
     while (n < nChildLen)
     {
-        pTmp = (*m_pChildList)[n].get();
+        pTmp = maChildList[n].get();
         pTmp->aAttrSet.Differentiate( aMrgSet );
 
-        if (!pTmp->m_pChildList && !pTmp->aAttrSet.Count() && !pTmp->nStyleNo)
+        if (pTmp->maChildList.empty() && !pTmp->aAttrSet.Count() && !pTmp->nStyleNo)
         {
-            m_pChildList->erase( m_pChildList->begin() + n );
+            maChildList.erase( maChildList.begin() + n );
             --nChildLen;
             continue;
         }
         ++n;
     }
-    if (m_pChildList->empty())
-    {
-        m_pChildList.reset();
-    }
 }
 void SvxRTFItemStackType::SetRTFDefaults( const SfxItemSet& rDefaults )
 {
diff --git a/include/editeng/svxrtf.hxx b/include/editeng/svxrtf.hxx
index 19a911303fa0..44723700d4a8 100644
--- a/include/editeng/svxrtf.hxx
+++ b/include/editeng/svxrtf.hxx
@@ -225,7 +225,7 @@ class SvxRTFItemStackType
     std::optional<EditNodeIdx>  mxStartNodeIdx;
     std::optional<EditNodeIdx>  mxEndNodeIdx;
     sal_Int32    nSttCnt, nEndCnt;
-    std::unique_ptr<SvxRTFItemStackList> m_pChildList;
+    SvxRTFItemStackList maChildList;
     sal_uInt16   nStyleNo;
 
     SvxRTFItemStackType(SvxRTFItemStackType const&) = delete;


More information about the Libreoffice-commits mailing list