summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2025-03-18 20:06:16 +0200
committerNoel Grandin <noelgrandin@gmail.com>2025-03-18 20:41:07 +0100
commite3bf8e0f58355d1460d190bd0b7751f133934573 (patch)
tree3d61411ce97df25180a6031f563192c1afa4740a /sw/source
parent808c56f1ea159209ee35d73c7995806df834f46e (diff)
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.grandin@collabora.co.uk>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/core/crsr/pam.cxx15
-rw-r--r--sw/source/core/doc/docredln.cxx25
2 files changed, 19 insertions, 21 deletions
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