sw/inc/pam.hxx                  |    2 ++
 sw/source/core/crsr/pam.cxx     |   15 +++++++++------
 sw/source/core/doc/docredln.cxx |   25 ++++++++++---------------
 3 files changed, 21 insertions(+), 21 deletions(-)

New commits:
commit e3bf8e0f58355d1460d190bd0b7751f133934573
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Tue Mar 18 20:06:16 2025 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Tue Mar 18 20:41:07 2025 +0100

    tdf#162343 speedup redline document
    
    we spend a lot of time searching for changes by calling GetTextOfArea.
    
    Speed that up by avoiding intermediate OUString and OUStringBuffer
    creation.
    
    Takes load time from 19 sec to 4 sec for me.
    
    Change-Id: Iae124d3668ddb874ddf12e209348c1f696e5549b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/183101
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sw/inc/pam.hxx b/sw/inc/pam.hxx
index 0fe773aa95b8..90d2f4679190 100644
--- a/sw/inc/pam.hxx
+++ b/sw/inc/pam.hxx
@@ -309,6 +309,8 @@ public:
     }
 
     OUString GetText() const;
+    // copy text into buffer
+    void AppendTextTo(rtl::OUStringBuffer& rBuffer) const;
     void InvalidatePaM();
     SwPaM* GetNext()
         { return GetNextInRing(); }
diff --git a/sw/source/core/crsr/pam.cxx b/sw/source/core/crsr/pam.cxx
index 408af6815cb2..398a9eb6e117 100644
--- a/sw/source/core/crsr/pam.cxx
+++ b/sw/source/core/crsr/pam.cxx
@@ -1292,8 +1292,13 @@ bool GoCurrSection( SwPaM & rPam, SwMoveFnCollection 
const & fnMove )
 
 OUString SwPaM::GetText() const
 {
-    OUStringBuffer aResult;
+    OUStringBuffer aResult(256);
+    AppendTextTo(aResult);
+    return aResult.makeStringAndClear();
+}
 
+void SwPaM::AppendTextTo(OUStringBuffer& rResult) const
+{
     SwNodeIndex aNodeIndex = Start()->nNode;
 
     // The first node can be already the end node.
@@ -1309,7 +1314,7 @@ OUString SwPaM::GetText() const
         {
             if (!bIsStartNode)
             {
-                aResult.append(CH_TXTATR_NEWLINE); // use newline for para 
break
+                rResult.append(CH_TXTATR_NEWLINE); // use newline for para 
break
             }
             const OUString& aTmpStr = pTextNode->GetText();
 
@@ -1323,11 +1328,11 @@ OUString SwPaM::GetText() const
                     ? End()->GetContentIndex()
                     : aTmpStr.getLength();
 
-                aResult.append(aTmpStr.subView(nStart, nEnd-nStart));
+                rResult.append(aTmpStr.subView(nStart, nEnd-nStart));
             }
             else
             {
-                aResult.append(aTmpStr);
+                rResult.append(aTmpStr);
             }
         }
 
@@ -1339,8 +1344,6 @@ OUString SwPaM::GetText() const
         ++aNodeIndex;
         bIsStartNode = false;
     }
-
-    return aResult.makeStringAndClear();
 }
 
 void SwPaM::InvalidatePaM()
diff --git a/sw/source/core/doc/docredln.cxx b/sw/source/core/doc/docredln.cxx
index c6bf7eb30f7f..ef8910e2179c 100644
--- a/sw/source/core/doc/docredln.cxx
+++ b/sw/source/core/doc/docredln.cxx
@@ -897,17 +897,15 @@ OUString SwRedlineTable::getTextOfArea(size_type 
rPosStart, size_type rPosEnd) c
     // But at import time some text is not present there yet
     // we have to collect them 1 by 1
 
-    OUString sRet = u""_ustr;
+    OUStringBuffer sRet(256);
 
     for (size_type nIdx = rPosStart; nIdx <= rPosEnd; ++nIdx)
     {
         SwRangeRedline* pRedline = (*this)[nIdx];
-        bool bStartWithNonTextNode = false;
 
-        OUString sNew;
         if (nullptr == pRedline->GetContentIdx())
         {
-            sNew = pRedline->GetText();
+            pRedline->AppendTextTo(sRet);
         }
         else // otherwise it is saved in pContentSect, e.g. during ODT import
         {
@@ -915,21 +913,18 @@ OUString SwRedlineTable::getTextOfArea(size_type 
rPosStart, size_type rPosEnd) c
                               
*pRedline->GetContentIdx()->GetNode().EndOfSectionNode());
             if (!aTmpPaM.Start()->nNode.GetNode().GetTextNode())
             {
-                bStartWithNonTextNode = true;
+                OUString sNew = aTmpPaM.GetText();
+                if (sNew[0] == CH_TXTATR_NEWLINE)
+                    sRet.append(sNew.subView(1));
+                else
+                    sRet.append(sNew);
             }
-            sNew = aTmpPaM.GetText();
-        }
-
-        if (bStartWithNonTextNode &&
-            sNew[0] == CH_TXTATR_NEWLINE)
-        {
-            sRet += sNew.subView(1);
+            else
+                aTmpPaM.AppendTextTo(sRet); // append contents of aTmpPaM to 
sRet
         }
-        else
-            sRet += sNew;
     }
 
-    return sRet;
+    return sRet.makeStringAndClear();
 }
 
 bool SwRedlineTable::isMoved(size_type rPos) const

Reply via email to