sw/source/core/text/atrhndl.hxx |    2 +-
 sw/source/core/text/atrstck.cxx |   18 +++++++++++-------
 2 files changed, 12 insertions(+), 8 deletions(-)

New commits:
commit f3628260e55baf871bd29922075f1498a80e438f
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Fri Oct 22 12:03:58 2021 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Fri Oct 22 15:37:25 2021 +0200

    tdf#145274 FILEOPEN: Text properties are lost
    
    Revert "tdf#135683 speedup SwAttrHandler"
    This reverts commit b62153753a9f21afb2a49110ef0459e427b0b01a
    
    SwAttrHandler::RemoveFromStack breaks the assumption I made in creating the 
above commit
    
    Change-Id: I20ab532e1eae98c94f7c579755285262d46f2f91
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124012
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/source/core/text/atrhndl.hxx b/sw/source/core/text/atrhndl.hxx
index 92d0153eefc3..6c719bf2cbaf 100644
--- a/sw/source/core/text/atrhndl.hxx
+++ b/sw/source/core/text/atrhndl.hxx
@@ -38,7 +38,7 @@ extern const sal_uInt8 StackPos[];
 class SwAttrHandler
 {
 private:
-    const SwTextAttr* m_aAttrStack[NUM_ATTRIBUTE_STACKS] {}; // stack 
collection
+    std::vector<const SwTextAttr*> m_aAttrStack[NUM_ATTRIBUTE_STACKS]; // 
stack collection
     const SfxPoolItem* m_pDefaultArray[ NUM_DEFAULT_VALUES ];
     const IDocumentSettingAccess* m_pIDocumentSettingAccess;
     const SwViewShell* m_pShell;
diff --git a/sw/source/core/text/atrstck.cxx b/sw/source/core/text/atrstck.cxx
index 430e2ea4527d..30a88c30110d 100644
--- a/sw/source/core/text/atrstck.cxx
+++ b/sw/source/core/text/atrstck.cxx
@@ -331,7 +331,7 @@ void SwAttrHandler::Init( const SfxPoolItem** pPoolItem, 
const SwAttrSet* pAS,
 void SwAttrHandler::Reset( )
 {
     for (auto& i : m_aAttrStack)
-        i = nullptr;
+        i.clear();
 }
 
 void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
@@ -380,7 +380,7 @@ void SwAttrHandler::PushAndChg( const SwTextAttr& rAttr, 
SwFont& rFnt )
 
 const SwTextAttr* SwAttrHandler::GetTop(sal_uInt16 nStack)
 {
-    return m_aAttrStack[nStack];
+    return m_aAttrStack[nStack].empty() ? nullptr : 
m_aAttrStack[nStack].back();
 }
 
 bool SwAttrHandler::Push( const SwTextAttr& rAttr, const SfxPoolItem& rItem )
@@ -402,18 +402,21 @@ bool SwAttrHandler::Push( const SwTextAttr& rAttr, const 
SfxPoolItem& rItem )
          || ( !pTopAttr->IsPriorityAttr()
               && !lcl_ChgHyperLinkColor(*pTopAttr, rItem, m_pShell, nullptr)))
     {
-        m_aAttrStack[nStack] = &rAttr;
+        m_aAttrStack[nStack].push_back(&rAttr);
         return true;
     }
 
+    const auto it = m_aAttrStack[nStack].end() - 1;
+    m_aAttrStack[nStack].insert(it, &rAttr);
     return false;
 }
 
 void SwAttrHandler::RemoveFromStack(sal_uInt16 nWhich, const SwTextAttr& rAttr)
 {
     auto& rStack = m_aAttrStack[StackPos[nWhich]];
-    if (rStack == &rAttr)
-        rStack = nullptr;
+    const auto it = std::find(rStack.begin(), rStack.end(), &rAttr);
+    if (it != rStack.end())
+        rStack.erase(it);
 }
 
 void SwAttrHandler::PopAndChg( const SwTextAttr& rAttr, SwFont& rFnt )
@@ -733,7 +736,7 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, 
SwFont& rFnt, bool bPush )
             // 2. top of two line stack ( or default attribute )is an
             //    deactivated two line attribute
             const bool bRuby =
-                nullptr != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ];
+                0 != m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
 
             if ( bRuby )
                 break;
@@ -757,7 +760,8 @@ void SwAttrHandler::FontChg(const SfxPoolItem& rItem, 
SwFont& rFnt, bool bPush )
         }
         case RES_CHRATR_TWO_LINES :
         {
-            bool bRuby = nullptr != m_aAttrStack[ StackPos[ 
RES_TXTATR_CJK_RUBY ] ];
+            bool bRuby = 0 !=
+                    m_aAttrStack[ StackPos[ RES_TXTATR_CJK_RUBY ] ].size();
 
             // two line is activated, if
             // 1. no ruby attribute is set and

Reply via email to