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

Noel Grandin (via logerrit) logerrit at kemper.freedesktop.org
Tue Aug 10 13:36:06 UTC 2021


 sw/source/core/txtnode/ndhints.cxx |   54 ++++++++++++++++++++++++-------------
 1 file changed, 36 insertions(+), 18 deletions(-)

New commits:
commit 4d50939a7b37cbaeceeddebabfc435190e079781
Author:     Noel Grandin <noel at peralex.com>
AuthorDate: Tue Aug 10 14:08:11 2021 +0200
Commit:     Noel Grandin <noel.grandin at collabora.co.uk>
CommitDate: Tue Aug 10 15:35:28 2021 +0200

    tdf#136991 Open RTF with colored text
    
    We spend most of the time in MergePortions, and the resorting is
    a significant part of that, so only resort if we actually have to.
    
    This shaves 10% off the load time for this document.
    
    Change-Id: I2380c5aa744f6d9c82195bb2a17ced2ce7616e9a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120269
    Tested-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>

diff --git a/sw/source/core/txtnode/ndhints.cxx b/sw/source/core/txtnode/ndhints.cxx
index cd136f21a9c5..194aafc95db1 100644
--- a/sw/source/core/txtnode/ndhints.cxx
+++ b/sw/source/core/txtnode/ndhints.cxx
@@ -411,36 +411,54 @@ bool SwpHints::Check(bool bPortionsMerged) const
 
 void SwpHints::Resort() const
 {
-    auto & rStartMap = const_cast<SwpHints*>(this)->m_HintsByStart;
-    std::sort(rStartMap.begin(), rStartMap.end(), CompareSwpHtStart);
-    auto & rEndMap = const_cast<SwpHints*>(this)->m_HintsByEnd;
-    std::sort(rEndMap.begin(), rEndMap.end(), CompareSwpHtEnd());
-    auto & rWhichStartMap = const_cast<SwpHints*>(this)->m_HintsByWhichAndStart;
-    std::sort(rWhichStartMap.begin(), rWhichStartMap.end(), CompareSwpHtWhichStart());
-    m_bStartMapNeedsSorting = false;
-    m_bEndMapNeedsSorting = false;
-    m_bWhichMapNeedsSorting = false;
+    if (m_bStartMapNeedsSorting)
+    {
+        auto & rStartMap = const_cast<SwpHints*>(this)->m_HintsByStart;
+        std::sort(rStartMap.begin(), rStartMap.end(), CompareSwpHtStart);
+        m_bStartMapNeedsSorting = false;
+    }
+    if (m_bEndMapNeedsSorting)
+    {
+        auto & rEndMap = const_cast<SwpHints*>(this)->m_HintsByEnd;
+        std::sort(rEndMap.begin(), rEndMap.end(), CompareSwpHtEnd());
+        m_bEndMapNeedsSorting = false;
+    }
+    if (m_bWhichMapNeedsSorting)
+    {
+        auto & rWhichStartMap = const_cast<SwpHints*>(this)->m_HintsByWhichAndStart;
+        std::sort(rWhichStartMap.begin(), rWhichStartMap.end(), CompareSwpHtWhichStart());
+        m_bWhichMapNeedsSorting = false;
+    }
 }
 
 void SwpHints::ResortStartMap() const
 {
-    auto & rStartMap = const_cast<SwpHints*>(this)->m_HintsByStart;
-    std::sort(rStartMap.begin(), rStartMap.end(), CompareSwpHtStart);
-    m_bStartMapNeedsSorting = false;
+    if (m_bStartMapNeedsSorting)
+    {
+        auto & rStartMap = const_cast<SwpHints*>(this)->m_HintsByStart;
+        std::sort(rStartMap.begin(), rStartMap.end(), CompareSwpHtStart);
+        m_bStartMapNeedsSorting = false;
+    }
 }
 
 void SwpHints::ResortEndMap() const
 {
-    auto & rEndMap = const_cast<SwpHints*>(this)->m_HintsByEnd;
-    std::sort(rEndMap.begin(), rEndMap.end(), CompareSwpHtEnd());
-    m_bEndMapNeedsSorting = false;
+    if (m_bEndMapNeedsSorting)
+    {
+        auto & rEndMap = const_cast<SwpHints*>(this)->m_HintsByEnd;
+        std::sort(rEndMap.begin(), rEndMap.end(), CompareSwpHtEnd());
+        m_bEndMapNeedsSorting = false;
+    }
 }
 
 void SwpHints::ResortWhichMap() const
 {
-    m_bWhichMapNeedsSorting = false;
-    auto & rWhichStartMap = const_cast<SwpHints*>(this)->m_HintsByWhichAndStart;
-    std::sort(rWhichStartMap.begin(), rWhichStartMap.end(), CompareSwpHtWhichStart());
+    if (m_bWhichMapNeedsSorting)
+    {
+        auto & rWhichStartMap = const_cast<SwpHints*>(this)->m_HintsByWhichAndStart;
+        std::sort(rWhichStartMap.begin(), rWhichStartMap.end(), CompareSwpHtWhichStart());
+        m_bWhichMapNeedsSorting = false;
+    }
 }
 
 size_t SwpHints::GetFirstPosSortedByWhichAndStart( sal_uInt16 nWhich ) const


More information about the Libreoffice-commits mailing list