[Libreoffice-commits] core.git: sw/inc sw/source

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Thu May 30 12:06:56 UTC 2019


 sw/inc/IDocumentContentOperations.hxx                   |    4 +
 sw/inc/ndtxt.hxx                                        |    3 -
 sw/source/core/doc/DocumentContentOperationsManager.cxx |   20 ++++---
 sw/source/core/inc/DocumentContentOperationsManager.hxx |    3 -
 sw/source/core/inc/rolbck.hxx                           |    3 -
 sw/source/core/txtnode/thints.cxx                       |    6 +-
 sw/source/core/undo/rolbck.cxx                          |    5 +
 sw/source/core/unocore/unoidx.cxx                       |   41 ++--------------
 8 files changed, 35 insertions(+), 50 deletions(-)

New commits:
commit 5a74ef3d249ea88cf0bf1f333014809f652a6a41
Author:     Noel Grandin <noel.grandin at collabora.co.uk>
AuthorDate: Thu May 30 12:12:43 2019 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Thu May 30 14:05:40 2019 +0200

    tdf#125372 writer, file with lots of hints very slow to open, part7
    
    Takes load time from 1m45 to 22s
    
    Instead of (1) taking a list of SwTextAttrs (2) invoking a method that
    inserts a new one (3) taking a new list and doing a delta on the list,
    just the information about the new SwTextAttr up the stack and avoid all
    that work.
    
    Change-Id: Iec88618af696299aaba65f43bc33b1a5f030fac0
    Reviewed-on: https://gerrit.libreoffice.org/73195
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/inc/IDocumentContentOperations.hxx b/sw/inc/IDocumentContentOperations.hxx
index f0b7a8d88497..f59b1f0eef89 100644
--- a/sw/inc/IDocumentContentOperations.hxx
+++ b/sw/inc/IDocumentContentOperations.hxx
@@ -38,6 +38,7 @@ class SwDrawFrameFormat;
 class SwFlyFrameFormat;
 class SwNodeIndex;
 class SwRootFrame;
+class SwTextAttr;
 
 namespace utl { class TransliterationWrapper; }
 namespace svt { class EmbeddedObjectRef; }
@@ -215,7 +216,8 @@ public:
     virtual bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem&,
                                 const SetAttrMode nFlags = SetAttrMode::DEFAULT,
                                 SwRootFrame const* pLayout = nullptr,
-                                bool bExpandCharToPara=false) = 0;
+                                bool bExpandCharToPara = false,
+                                SwTextAttr **ppNewTextAttr = nullptr) = 0;
 
     virtual void InsertItemSet (const SwPaM &rRg, const SfxItemSet&,
         const SetAttrMode nFlags = SetAttrMode::DEFAULT,
diff --git a/sw/inc/ndtxt.hxx b/sw/inc/ndtxt.hxx
index debe937dd0bf..d8ab09b60f23 100644
--- a/sw/inc/ndtxt.hxx
+++ b/sw/inc/ndtxt.hxx
@@ -295,7 +295,8 @@ public:
        set them only in AutoAttrSet (SwContentNode::SetAttr). */
     bool SetAttr( const SfxItemSet& rSet,
                   sal_Int32 nStt, sal_Int32 nEnd,
-                  const SetAttrMode nMode = SetAttrMode::DEFAULT );
+                  const SetAttrMode nMode = SetAttrMode::DEFAULT,
+                  SwTextAttr **ppNewTextAttr = nullptr);
     /** Query the attributes of textnode over the range.
        Introduce 4th optional parameter <bMergeIndentValuesOfNumRule>.
        If <bMergeIndentValuesOfNumRule> == true, the indent attributes of
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 7e2d3e415148..f15bb96ba7ae 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -1101,7 +1101,8 @@ namespace //local functions originally from docfmt.cxx
         const SetAttrMode nFlags,
         SwUndoAttr *const pUndo,
         SwRootFrame const*const pLayout,
-        const bool bExpandCharToPara=false)
+        const bool bExpandCharToPara,
+        SwTextAttr **ppNewTextAttr)
     {
         // Divide the Sets (for selections in Nodes)
         const SfxItemSet* pCharSet = nullptr;
@@ -1233,7 +1234,7 @@ namespace //local functions originally from docfmt.cxx
                 {
                     SwRegHistory history( pNode, *pNode, pHistory );
                     bRet = history.InsertItems(
-                        aTextSet, rSt.GetIndex(), rSt.GetIndex(), nFlags ) || bRet;
+                        aTextSet, rSt.GetIndex(), rSt.GetIndex(), nFlags, /*ppNewTextAttr*/nullptr ) || bRet;
 
                     if (bRet && (pDoc->getIDocumentRedlineAccess().IsRedlineOn() || (!pDoc->getIDocumentRedlineAccess().IsIgnoreRedline()
                                     && !pDoc->getIDocumentRedlineAccess().GetRedlineTable().empty())))
@@ -1272,7 +1273,7 @@ namespace //local functions originally from docfmt.cxx
                                     ? pEnd->nContent.GetIndex()
                                     : pNode->Len();
                     SwRegHistory history( pNode, *pNode, pHistory );
-                    bRet = history.InsertItems( aTextSet, nInsCnt, nEnd, nFlags )
+                    bRet = history.InsertItems( aTextSet, nInsCnt, nEnd, nFlags, ppNewTextAttr )
                            || bRet;
 
                     if (bRet && (pDoc->getIDocumentRedlineAccess().IsRedlineOn() || (!pDoc->getIDocumentRedlineAccess().IsIgnoreRedline()
@@ -1474,7 +1475,7 @@ namespace //local functions originally from docfmt.cxx
 
                 // the SwRegHistory inserts the attribute into the TextNode!
                 SwRegHistory history( pNode, *pNode, pHistory );
-                bRet = history.InsertItems( *pCharSet, nMkPos, nPtPos, nFlags )
+                bRet = history.InsertItems( *pCharSet, nMkPos, nPtPos, nFlags, /*ppNewTextAttr*/nullptr )
                     || bRet;
 
                 if( pDoc->getIDocumentRedlineAccess().IsRedlineOn() )
@@ -1528,7 +1529,7 @@ namespace //local functions originally from docfmt.cxx
                 {
                     SwRegHistory history( pNode, *pNode, pHistory );
                     bRet = history.InsertItems(*pCharSet,
-                            pStt->nContent.GetIndex(), aCntEnd.GetIndex(), nFlags)
+                            pStt->nContent.GetIndex(), aCntEnd.GetIndex(), nFlags, /*ppNewTextAttr*/nullptr)
                         || bRet;
                 }
 
@@ -1588,7 +1589,7 @@ namespace //local functions originally from docfmt.cxx
                     {
                         SwRegHistory history( pNode, *pNode, pHistory );
                         (void)history.InsertItems(*pCharSet,
-                                0, aCntEnd.GetIndex(), nFlags);
+                                0, aCntEnd.GetIndex(), nFlags, /*ppNewTextAttr*/nullptr);
                     }
 
                     if( pOtherSet && pOtherSet->Count() )
@@ -3214,7 +3215,8 @@ bool DocumentContentOperationsManager::InsertPoolItem(
     const SfxPoolItem &rHt,
     const SetAttrMode nFlags,
     SwRootFrame const*const pLayout,
-    const bool bExpandCharToPara)
+    const bool bExpandCharToPara,
+    SwTextAttr **ppNewTextAttr)
 {
     if (utl::ConfigManager::IsFuzzing())
         return false;
@@ -3229,7 +3231,7 @@ bool DocumentContentOperationsManager::InsertPoolItem(
 
     SfxItemSet aSet( m_rDoc.GetAttrPool(), {{rHt.Which(), rHt.Which()}} );
     aSet.Put( rHt );
-    const bool bRet = lcl_InsAttr(&m_rDoc, rRg, aSet, nFlags, pUndoAttr.get(), pLayout, bExpandCharToPara);
+    const bool bRet = lcl_InsAttr(&m_rDoc, rRg, aSet, nFlags, pUndoAttr.get(), pLayout, bExpandCharToPara, ppNewTextAttr);
 
     if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
     {
@@ -3254,7 +3256,7 @@ void DocumentContentOperationsManager::InsertItemSet ( const SwPaM &rRg, const S
         pUndoAttr.reset(new SwUndoAttr( rRg, rSet, nFlags ));
     }
 
-    bool bRet = lcl_InsAttr(&m_rDoc, rRg, rSet, nFlags, pUndoAttr.get(), pLayout);
+    bool bRet = lcl_InsAttr(&m_rDoc, rRg, rSet, nFlags, pUndoAttr.get(), pLayout, /*bExpandCharToPara*/false, /*ppNewTextAttr*/nullptr );
 
     if (m_rDoc.GetIDocumentUndoRedo().DoesUndo())
     {
diff --git a/sw/source/core/inc/DocumentContentOperationsManager.hxx b/sw/source/core/inc/DocumentContentOperationsManager.hxx
index e276d4e61238..f02bf2fb46e7 100644
--- a/sw/source/core/inc/DocumentContentOperationsManager.hxx
+++ b/sw/source/core/inc/DocumentContentOperationsManager.hxx
@@ -89,7 +89,8 @@ public:
     bool InsertPoolItem(const SwPaM &rRg, const SfxPoolItem&,
                         const SetAttrMode nFlags = SetAttrMode::DEFAULT,
                         SwRootFrame const* pLayout = nullptr,
-                        bool bExpandCharToPara=false) override;
+                        bool bExpandCharToPara = false,
+                        SwTextAttr **ppNewTextAttr = nullptr) override;
 
     void InsertItemSet (const SwPaM &rRg, const SfxItemSet&,
         const SetAttrMode nFlags = SetAttrMode::DEFAULT,
diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx
index eafb74fb303d..5a1613efb4df 100644
--- a/sw/source/core/inc/rolbck.hxx
+++ b/sw/source/core/inc/rolbck.hxx
@@ -416,7 +416,8 @@ public:
     /// @return true if at least 1 item was inserted
     bool InsertItems( const SfxItemSet& rSet,
         sal_Int32 const nStart, sal_Int32 const nEnd,
-        SetAttrMode const nFlags );
+        SetAttrMode const nFlags,
+        SwTextAttr **ppNewTextAttr );
 
     void AddHint( SwTextAttr* pHt, const bool bNew );
 
diff --git a/sw/source/core/txtnode/thints.cxx b/sw/source/core/txtnode/thints.cxx
index a53ae1cf0593..3d55ed251f2b 100644
--- a/sw/source/core/txtnode/thints.cxx
+++ b/sw/source/core/txtnode/thints.cxx
@@ -1836,7 +1836,8 @@ bool SwTextNode::SetAttr(
     const SfxItemSet& rSet,
     const sal_Int32 nStt,
     const sal_Int32 nEnd,
-    const SetAttrMode nMode )
+    const SetAttrMode nMode,
+    SwTextAttr **ppNewTextAttr )
 {
     if( !rSet.Count() )
         return false;
@@ -1931,6 +1932,9 @@ bool SwTextNode::SetAttr(
                                 const_cast<SfxPoolItem&>(*pItem), nStt, nEnd );
                         if ( pNew )
                         {
+                            // store the first one we create into the pp
+                            if (ppNewTextAttr && !*ppNewTextAttr)
+                                *ppNewTextAttr = pNew;
                             if ( nEnd != nStt && !pNew->GetEnd() )
                             {
                                 OSL_FAIL("Attribute without end, but area marked");
diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx
index 1fc7850b6de1..48fe37b27b7a 100644
--- a/sw/source/core/undo/rolbck.cxx
+++ b/sw/source/core/undo/rolbck.cxx
@@ -1350,7 +1350,8 @@ void SwRegHistory::AddHint( SwTextAttr* pHt, const bool bNew )
 }
 
 bool SwRegHistory::InsertItems( const SfxItemSet& rSet,
-    sal_Int32 const nStart, sal_Int32 const nEnd, SetAttrMode const nFlags )
+    sal_Int32 const nStart, sal_Int32 const nEnd, SetAttrMode const nFlags,
+    SwTextAttr **ppNewTextAttr )
 {
     if( !rSet.Count() )
         return false;
@@ -1367,7 +1368,7 @@ bool SwRegHistory::InsertItems( const SfxItemSet& rSet,
         pTextNode->GetOrCreateSwpHints().Register(this);
     }
 
-    const bool bInserted = pTextNode->SetAttr( rSet, nStart, nEnd, nFlags );
+    const bool bInserted = pTextNode->SetAttr( rSet, nStart, nEnd, nFlags, ppNewTextAttr );
 
     // Caution: The array can be deleted when inserting an attribute!
     // This can happen when the value that should be added first deletes
diff --git a/sw/source/core/unocore/unoidx.cxx b/sw/source/core/unocore/unoidx.cxx
index 31c1474f84c7..6ac2e5f33232 100644
--- a/sw/source/core/unocore/unoidx.cxx
+++ b/sw/source/core/unocore/unoidx.cxx
@@ -1944,44 +1944,17 @@ void SwXDocumentIndexMark::Impl::InsertTOXMark(
             | SetAttrMode::DONTEXPAND)
         : SetAttrMode::DONTEXPAND;
 
-    std::vector<SwTextAttr *> oldMarks;
-    if (bMark)
-    {
-        oldMarks = rPam.GetNode().GetTextNode()->GetTextAttrsAt(
-            rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK);
-    }
-
-    pDoc->getIDocumentContentOperations().InsertPoolItem(rPam, rMark, nInsertFlags);
+    // rMark gets copied into the document pool;
+    // pNewTextAttr comes back with the real format
+    SwTextAttr *pNewTextAttr = nullptr;
+    pDoc->getIDocumentContentOperations().InsertPoolItem(rPam, rMark, nInsertFlags,
+            /*pLayout*/nullptr, /*bExpandCharToPara*/false, &pNewTextAttr);
     if (bMark && *rPam.GetPoint() > *rPam.GetMark())
     {
         rPam.Exchange();
     }
 
-    // rMark was copied into the document pool; now retrieve real format...
-    SwTextAttr * pTextAttr(nullptr);
-    if (bMark)
-    {
-        // #i107672#
-        // ensure that we do not retrieve a different mark at the same position
-        std::vector<SwTextAttr *> const newMarks(
-            rPam.GetNode().GetTextNode()->GetTextAttrsAt(
-                rPam.GetPoint()->nContent.GetIndex(), RES_TXTATR_TOXMARK));
-        std::vector<SwTextAttr *>::const_iterator const iter(
-            std::find_if(newMarks.begin(), newMarks.end(),
-                NotContainedIn<SwTextAttr *>(oldMarks)));
-        assert(newMarks.end() != iter);
-        if (newMarks.end() != iter)
-        {
-            pTextAttr = *iter;
-        }
-    }
-    else
-    {
-        pTextAttr = rPam.GetNode().GetTextNode()->GetTextAttrForCharAt(
-            rPam.GetPoint()->nContent.GetIndex()-1, RES_TXTATR_TOXMARK );
-    }
-
-    if (!pTextAttr)
+    if (!pNewTextAttr)
     {
         throw uno::RuntimeException(
             "SwXDocumentIndexMark::InsertTOXMark(): cannot insert attribute",
@@ -1989,7 +1962,7 @@ void SwXDocumentIndexMark::Impl::InsertTOXMark(
     }
 
     m_pDoc = pDoc;
-    m_pTOXMark = &pTextAttr->GetTOXMark();
+    m_pTOXMark = &pNewTextAttr->GetTOXMark();
     m_pTOXType = &rTOXType;
     m_aListener.EndListeningAll();
     m_aListener.StartListening(const_cast<SwTOXMark*>(m_pTOXMark));


More information about the Libreoffice-commits mailing list