sw/source/core/text/itrform2.cxx   |    1 +
 vcl/source/gdi/CommonSalLayout.cxx |    9 ++++++---
 2 files changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 6594b279a926e497261a4e802a5e74d2f3b97369
Author:     Jonathan Clark <jonat...@libreoffice.org>
AuthorDate: Tue Sep 3 05:49:28 2024 -0600
Commit:     Jonathan Clark <jonat...@libreoffice.org>
CommitDate: Tue Sep 3 21:32:00 2024 +0200

    tdf#92064 sw: Improve large paragraph layout performance
    
    This change includes the following scalability improvements for
    documents containing extremely large paragraphs:
    
    - Reduces the size of layout contexts to account for LF control chars.
    
    - Due to typical access patterns while laying out paragraphs, VCL was
      making O(n^2) calls to vcl::ScriptRun::next(). VCL now uses an
      existing global LRU cache for script runs, avoiding much of this
      overhead.
    
    Change-Id: Iee03938683c95776a817d4819fe9a43c65a7c3fc
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/172801
    Tested-by: Jenkins
    Reviewed-by: Jonathan Clark <jonat...@libreoffice.org>

diff --git a/sw/source/core/text/itrform2.cxx b/sw/source/core/text/itrform2.cxx
index 4b3778dd6ed4..c6c68f8041fa 100644
--- a/sw/source/core/text/itrform2.cxx
+++ b/sw/source/core/text/itrform2.cxx
@@ -1460,6 +1460,7 @@ SwTextPortion *SwTextFormatter::NewTextPortion( 
SwTextFormatInfo &rInf )
                 case CH_TXTATR_BREAKWORD:
                 case CH_TXTATR_INWORD:
                 case CH_TXTATR_TAB:
+                case CH_TXTATR_NEWLINE:
                 case CH_TXT_ATR_INPUTFIELDSTART:
                 case CH_TXT_ATR_INPUTFIELDEND:
                 case CH_TXT_ATR_FORMELEMENT:
diff --git a/vcl/source/gdi/CommonSalLayout.cxx 
b/vcl/source/gdi/CommonSalLayout.cxx
index 0602ecca3fc8..a932dd54b16f 100644
--- a/vcl/source/gdi/CommonSalLayout.cxx
+++ b/vcl/source/gdi/CommonSalLayout.cxx
@@ -382,7 +382,7 @@ bool 
GenericSalLayout::LayoutText(vcl::text::ImplLayoutArgs& rArgs, const SalLay
     const int nLength = rArgs.mrStr.getLength();
     const sal_Unicode *pStr = rArgs.mrStr.getStr();
 
-    std::optional<vcl::text::TextLayoutCache> oNewScriptRun;
+    std::shared_ptr<const vcl::text::TextLayoutCache> pNewScriptRun;
     vcl::text::TextLayoutCache const* pTextLayout;
     if (rArgs.m_pTextLayoutCache)
     {
@@ -390,8 +390,11 @@ bool 
GenericSalLayout::LayoutText(vcl::text::ImplLayoutArgs& rArgs, const SalLay
     }
     else
     {
-        oNewScriptRun.emplace(pStr, rArgs.mnEndCharPos);
-        pTextLayout = &*oNewScriptRun;
+        // tdf#92064, tdf#162663:
+        // Also use the global LRU cache for full string script runs.
+        // This obviates O(n^2) calls to vcl::ScriptRun::next() when laying 
out large paragraphs.
+        pNewScriptRun = vcl::text::TextLayoutCache::Create(rArgs.mrStr);
+        pTextLayout = pNewScriptRun.get();
     }
 
     // nBaseOffset is used to align vertical text to the center of rotated

Reply via email to