sw/qa/extras/layout/layout4.cxx                 |    9 +
 sw/source/core/inc/swcache.hxx                  |    8 -
 sw/source/core/inc/txtfrm.hxx                   |   33 +---
 sw/source/core/layout/flowfrm.cxx               |    2 
 sw/source/core/layout/frmtool.cxx               |    4 
 sw/source/core/text/EnhancedPDFExportHelper.cxx |    5 
 sw/source/core/text/frmform.cxx                 |   29 +---
 sw/source/core/text/frmpaint.cxx                |    7 -
 sw/source/core/text/txtcache.cxx                |  159 +-----------------------
 sw/source/core/text/txtcache.hxx                |   62 ---------
 sw/source/core/text/txtfrm.cxx                  |   27 +---
 sw/source/core/text/txtinit.cxx                 |    8 -
 sw/source/core/view/viewsh.cxx                  |    5 
 sw/source/core/view/vnew.cxx                    |    7 -
 14 files changed, 58 insertions(+), 307 deletions(-)

New commits:
commit 62af1f9b3c11288f932447d1076e97c7d4454e40
Author:     Noel Grandin <[email protected]>
AuthorDate: Thu Oct 2 21:03:26 2025 +0200
Commit:     Noel Grandin <[email protected]>
CommitDate: Tue Oct 7 12:47:12 2025 +0200

    remove SwParaPortion cache
    
    No longer necessary with modern machines, and it makes
    certain operations considerably faster.
    I tested this with a 1000 page document, and saw only
    a moderate increase in memory usage.
    
    Note that there is something weird going on with one
    of the unit tests. I worked around it for now.
    
    Change-Id: Ife42e444da9bbb2ed543cfadec34ecfe5ad0c515
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/191934
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <[email protected]>

diff --git a/sw/qa/extras/layout/layout4.cxx b/sw/qa/extras/layout/layout4.cxx
index 7c7abeb4abea..56865788eb5c 100644
--- a/sw/qa/extras/layout/layout4.cxx
+++ b/sw/qa/extras/layout/layout4.cxx
@@ -355,6 +355,15 @@ CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testTdf156419)
 CPPUNIT_TEST_FIXTURE(SwLayoutWriter4, testTdf145826)
 {
     createSwDoc("tdf145826.odt");
+
+    // Something weird going on here. If I run this unit test by itself, it 
passes fine.
+    // But when run as part of the test suite, it needs the following 
dispatchCommand
+    // in order to pass.
+    uno::Sequence<beans::PropertyValue> argsSH(
+        comphelper::InitPropertySequence({ { "ShowHiddenParagraphs", 
uno::Any(true) } }));
+    dispatchCommand(mxComponent, ".uno:ShowHiddenParagraphs", argsSH);
+    Scheduler::ProcessEventsToIdle();
+
     xmlDocUniquePtr pXmlDoc = parseLayoutDump();
     CPPUNIT_ASSERT(pXmlDoc);
 
diff --git a/sw/source/core/inc/swcache.hxx b/sw/source/core/inc/swcache.hxx
index df8ed2a64ebf..e666c91f82e4 100644
--- a/sw/source/core/inc/swcache.hxx
+++ b/sw/source/core/inc/swcache.hxx
@@ -120,14 +120,6 @@ public:
     sal_uInt16 size() { return m_aCacheObjects.size(); }
 };
 
-/// Try to prevent visible SwParaPortions from being deleted.
-class SwSaveSetLRUOfst
-{
-public:
-    SwSaveSetLRUOfst();
-    ~SwSaveSetLRUOfst();
-};
-
 /**
  * The Cache object base class
  * Users of the Cache must derive a class from the SwCacheObj and store
diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx
index c43f78e199a2..8a51b206101b 100644
--- a/sw/source/core/inc/txtfrm.hxx
+++ b/sw/source/core/inc/txtfrm.hxx
@@ -177,13 +177,6 @@ class SW_DLLPUBLIC SwTextFrame final : public 
SwContentFrame
     friend class TextFrameLockGuard; // May Lock()/Unlock()
     friend bool sw_ChangeOffset(SwTextFrame* pFrame, TextFrameIndex nNew);
 
-    /// SwLineLayout cache: the lines are not actually owned by the SwTextFrame
-    /// but by this SwCache, so they will be deleted in large documents
-    /// if there are too many of them, but the "valid" flags of the frame
-    /// will still be set; GetFormatted() is the function that forces
-    /// recreation of the SwLineLayout by Format() if necessary.
-    static SwCache *s_pTextCache;
-
     sal_Int32  mnAllLines        :24; // Line count for the Paint (including 
nThisLines)
     sal_Int32  mnThisLines       :8; // Count of Lines of the Frame
 
@@ -204,6 +197,10 @@ class SW_DLLPUBLIC SwTextFrame final : public 
SwContentFrame
     // It is NOT used for the determination of printing area.
     SwTwips mnAdditionalFirstLineOffset;
 
+    // Should be a unique_ptr, but code like CalcAdditionalFirstLineOffset 
wants to play games
+    // where it swaps out and then restores the SwParaPortion.
+    std::shared_ptr<SwParaPortion> m_xParaPortion;
+
     /// redline merge data
     std::unique_ptr<sw::MergedPara> m_pMergedPara;
 
@@ -211,8 +208,6 @@ class SW_DLLPUBLIC SwTextFrame final : public SwContentFrame
     TextFrameIndex mnNoHyphOffset; // Is the offset of the last line with 
disabled or limited hyphenation
     sal_Int16 mnNoHyphEndZone;     // size of end zone (-1 means disabled 
hyphenation)
 
-    sal_uInt16 mnCacheIndex; // Index into the cache, USHRT_MAX if there's 
definitely no fitting object in the cache
-
     // Separates the Master and creates a Follow or adjusts the data in the 
Follow
     void AdjustFollow_( SwTextFormatter &rLine, TextFrameIndex nOffset,
                                TextFrameIndex nStrEnd, bool bDontJoin );
@@ -301,7 +296,7 @@ class SW_DLLPUBLIC SwTextFrame final : public SwContentFrame
     bool GetDropRect_( SwRect &rRect ) const;
 
     // returns the old SwParaPortion, if present
-    std::unique_ptr<SwParaPortion> SetPara(std::unique_ptr<SwParaPortion> 
xNew);
+    std::shared_ptr<SwParaPortion> SetPara(std::shared_ptr<SwParaPortion> 
xNew);
 
     bool IsFootnoteNumFrame_() const;
 
@@ -522,10 +517,11 @@ public:
     /// Test grow
     inline SwTwips GrowTst( const SwTwips nGrow, SwResizeLimitReason& );
 
-    SwParaPortion *GetPara();
+    inline SwParaPortion *GetPara() { return m_xParaPortion.get(); }
     inline const SwParaPortion *GetPara() const;
-    inline bool HasPara() const;
-    bool HasPara_() const;
+    inline bool HasPara() const { return bool(m_xParaPortion); }
+    // ensure the SwParaPortion exists
+    SwParaPortion* EnsurePara();
 
     /// map position in potentially merged text frame to SwPosition
     std::pair<SwTextNode*, sal_Int32> MapViewToModel(TextFrameIndex nIndex) 
const;
@@ -632,12 +628,6 @@ public:
     bool GetDropRect( SwRect &rRect ) const
     { return HasPara() && GetDropRect_( rRect ); }
 
-    static SwCache *GetTextCache() { return s_pTextCache; }
-    static void     SetTextCache( SwCache *pNew ) { s_pTextCache = pNew; }
-
-    sal_uInt16 GetCacheIdx() const { return mnCacheIndex; }
-    void   SetCacheIdx( const sal_uInt16 nNew ) { mnCacheIndex = nNew; }
-
     /// Removes the Line information from the Cache but retains the entry 
itself
     void ClearPara();
     /// Removes this frame completely from the Cache
@@ -859,11 +849,6 @@ inline const SwParaPortion *SwTextFrame::GetPara() const
     return const_cast<SwTextFrame*>(this)->GetPara();
 }
 
-inline bool SwTextFrame::HasPara() const
-{
-    return mnCacheIndex!=USHRT_MAX && HasPara_();
-}
-
 inline SwTwips SwTextFrame::GrowTst(const SwTwips nGrow, SwResizeLimitReason& 
reason)
 {
     return Grow(nGrow, reason, true, false);
diff --git a/sw/source/core/layout/flowfrm.cxx 
b/sw/source/core/layout/flowfrm.cxx
index f666d80fce27..5e1a926b785f 100644
--- a/sw/source/core/layout/flowfrm.cxx
+++ b/sw/source/core/layout/flowfrm.cxx
@@ -647,7 +647,7 @@ bool SwFlowFrame::PasteTree( SwFrame *pStart, SwLayoutFrame 
*pParent, SwFrame *p
         // The CacheIdx idea seems to be a bit risky!
         if ( pFloat->IsTextFrame() )
         {
-            if ( static_cast<SwTextFrame*>(pFloat)->GetCacheIdx() != USHRT_MAX 
)
+            if ( static_cast<SwTextFrame*>(pFloat)->HasPara() )
                 static_cast<SwTextFrame*>(pFloat)->Init();    // I'm his 
friend.
         }
         else
diff --git a/sw/source/core/layout/frmtool.cxx 
b/sw/source/core/layout/frmtool.cxx
index f5b4d4c5f3eb..4183cd482587 100644
--- a/sw/source/core/layout/frmtool.cxx
+++ b/sw/source/core/layout/frmtool.cxx
@@ -3100,7 +3100,7 @@ void RestoreContent( SwFrame *pSav, SwLayoutFrame 
*pParent, SwFrame *pSibling )
         if ( pSav->IsContentFrame() )
         {
             if ( pSav->IsTextFrame() &&
-                 static_cast<SwTextFrame*>(pSav)->GetCacheIdx() != USHRT_MAX )
+                 static_cast<SwTextFrame*>(pSav)->HasPara() )
                 static_cast<SwTextFrame*>(pSav)->Init();  // I am its friend
 
             if ( pPage && pSav->GetDrawObjs() )
@@ -3114,7 +3114,7 @@ void RestoreContent( SwFrame *pSav, SwLayoutFrame 
*pParent, SwFrame *pSibling )
                 {   if ( pPage && pBlub->GetDrawObjs() )
                         ::lcl_AddObjsToPage( pBlub, pPage );
                     if( pBlub->IsTextFrame() && 
static_cast<SwTextFrame*>(pBlub)->HasFootnote() &&
-                         static_cast<SwTextFrame*>(pBlub)->GetCacheIdx() != 
USHRT_MAX )
+                         static_cast<SwTextFrame*>(pBlub)->HasPara() )
                         static_cast<SwTextFrame*>(pBlub)->Init(); // I am its 
friend
                     pBlub = pBlub->GetNextContentFrame();
                 } while ( pBlub && 
static_cast<SwLayoutFrame*>(pSav)->IsAnLower( pBlub ));
diff --git a/sw/source/core/text/EnhancedPDFExportHelper.cxx 
b/sw/source/core/text/EnhancedPDFExportHelper.cxx
index 5c877a4bc422..05dd9b38ea30 100644
--- a/sw/source/core/text/EnhancedPDFExportHelper.cxx
+++ b/sw/source/core/text/EnhancedPDFExportHelper.cxx
@@ -2339,11 +2339,6 @@ void 
SwEnhancedPDFExportHelper::EnhancedPDFExport(LanguageType const eLanguageDe
     const bool bOldLockView = mrSh.IsViewLocked();
     mrSh.LockView( true );
 
-    // tdf#133976 speeds up export greatly
-    SwTextFrame::GetTextCache()->IncreaseMax( 10000 );
-    const ::comphelper::ScopeGuard aGuard(
-        []() mutable { SwTextFrame::GetTextCache()->DecreaseMax( 10000 ); } );
-
     if ( !mbEditEngineOnly )
     {
         assert(pPDFExtOutDevData->GetSwPDFState() == nullptr);
diff --git a/sw/source/core/text/frmform.cxx b/sw/source/core/text/frmform.cxx
index 17e55bf5ba48..fca5696bfb07 100644
--- a/sw/source/core/text/frmform.cxx
+++ b/sw/source/core/text/frmform.cxx
@@ -41,7 +41,6 @@
 #include <fmtanchr.hxx>
 #include "itrform2.hxx"
 #include "widorp.hxx"
-#include "txtcache.hxx"
 #include <sectfrm.hxx>
 #include <rootfrm.hxx>
 #include <frmfmt.hxx>
@@ -982,10 +981,7 @@ bool SwTextFrame::CalcPreps()
                 if( !CalcPrepFootnoteAdjust() )
                 {
                     if( bPrepMustFit )
-                    {
-                        SwTextLineAccess aAccess( this );
-                        aAccess.GetPara()->SetPrepMustFit(true);
-                    }
+                        EnsurePara()->SetPrepMustFit(true);
                     return false;
                 }
             }
@@ -2115,9 +2111,8 @@ void SwTextFrame::Format( vcl::RenderContext* 
pRenderContext, const SwBorderAttr
     if( aRectFnSet.GetWidth(getFramePrintArea()) <= 0 )
     {
         // If MustFit is set, we shrink to the Upper's bottom edge if needed.
-        SwTextLineAccess aAccess( this );
 
-        if( aAccess.GetPara()->IsPrepMustFit() )
+        if( EnsurePara()->IsPrepMustFit() )
         {
             const SwTwips nLimit = aRectFnSet.GetPrtBottom(*GetUpper());
             const SwTwips nDiff = - aRectFnSet.BottomDist( getFrameArea(), 
nLimit );
@@ -2208,8 +2203,11 @@ void SwTextFrame::Format( vcl::RenderContext* 
pRenderContext, const SwBorderAttr
             }
         }
 
-        SwTextLineAccess aAccess( this );
-        const bool bNew = !aAccess.IsAvailable();
+        const bool bNew = !m_xParaPortion;
+        EnsurePara(); // force creation of m_xParaPortion
+        // We have to work with a shared_ptr here because code like 
CalcAdditionalFirstLineOffset
+        // wants to swap out and then restore the SwParaPortion underneath us.
+        std::shared_ptr<SwParaPortion> xPara = m_xParaPortion;
         const bool bSetOffset =
             (GetOffset() && GetOffset() > 
TextFrameIndex(GetText().getLength()));
 
@@ -2217,12 +2215,12 @@ void SwTextFrame::Format( vcl::RenderContext* 
pRenderContext, const SwBorderAttr
             ; // nothing
         // We return if already formatted, but if the TextFrame was just 
created
         // and does not have any format information
-        else if( !bNew && !aAccess.GetPara()->GetReformat().Len() )
+        else if( !bNew && !xPara->GetReformat().Len() )
         {
             if 
(GetTextNodeForParaProps()->GetSwAttrSet().GetRegister().GetValue())
             {
-                aAccess.GetPara()->SetPrepAdjust();
-                aAccess.GetPara()->SetPrep();
+                xPara->SetPrepAdjust();
+                xPara->SetPrep();
                 CalcPreps();
             }
             SetWidow( false );
@@ -2267,7 +2265,7 @@ void SwTextFrame::Format( vcl::RenderContext* 
pRenderContext, const SwBorderAttr
                 {
                     nexts.push_back(pNext);
                 }
-                FormatImpl(pRenderContext, aAccess.GetPara(), 
intersectingObjs);
+                FormatImpl(pRenderContext, xPara.get(), intersectingObjs);
                 if( pFootnoteBoss && nFootnoteHeight )
                 {
                     const SwFootnoteContFrame* pCont = 
pFootnoteBoss->FindFootnoteCont();
@@ -2429,9 +2427,8 @@ bool SwTextFrame::FormatQuick( bool bForceQuickFormat )
         ( ( IsVertical() ? getFramePrintArea().Width() : 
getFramePrintArea().Height() ) && IsHiddenNow() ) )
         return false;
 
-    SwTextLineAccess aAccess( this );
-    SwParaPortion *pPara = aAccess.GetPara();
-    if( !pPara )
+    SwParaPortion *pPara = GetPara();
+    if (!pPara)
         return false;
 
     SwFrameSwapper aSwapper( this, true );
diff --git a/sw/source/core/text/frmpaint.cxx b/sw/source/core/text/frmpaint.cxx
index 623857d5cd35..e7b35b8a49ff 100644
--- a/sw/source/core/text/frmpaint.cxx
+++ b/sw/source/core/text/frmpaint.cxx
@@ -35,7 +35,6 @@
 #include <txtfrm.hxx>
 #include "itrpaint.hxx"
 #include "txtpaint.hxx"
-#include "txtcache.hxx"
 #include <flyfrm.hxx>
 #include "redlnitr.hxx"
 #include <redline.hxx>
@@ -375,8 +374,7 @@ void SwTextFrame::PaintExtraData( const SwRect &rRect ) 
const
     {
         TextFrameLockGuard aLock(const_cast<SwTextFrame*>(this));
 
-        SwTextLineAccess aAccess( this );
-        aAccess.GetPara();
+        const_cast<SwTextFrame*>(this)->EnsurePara();
 
         SwTextPaintInfo aInf( const_cast<SwTextFrame*>(this), rRect );
 
@@ -725,8 +723,7 @@ void SwTextFrame::PaintSwFrame(vcl::RenderContext& 
rRenderContext, SwRect const&
     // rRepaint is set. Indeed, we cannot avoid this problem from a formal
     // perspective. Luckily we can assume rRepaint to be empty when we need
     // paint the while Frame.
-    SwTextLineAccess aAccess( this );
-    SwParaPortion *pPara = aAccess.GetPara();
+    SwParaPortion *pPara = const_cast<SwTextFrame*>(this)->EnsurePara();
 
     SwRepaint &rRepaint = pPara->GetRepaint();
 
diff --git a/sw/source/core/text/txtcache.cxx b/sw/source/core/text/txtcache.cxx
index 4a0d226838ec..900a1d5b3849 100644
--- a/sw/source/core/text/txtcache.cxx
+++ b/sw/source/core/text/txtcache.cxx
@@ -17,7 +17,6 @@
  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
  */
 
-#include "txtcache.hxx"
 #include <txtfrm.hxx>
 #include "porlay.hxx"
 
@@ -25,174 +24,40 @@
 #include <osl/diagnose.h>
 #include <view.hxx>
 
-SwTextLine::SwTextLine(SwTextFrame const *pFrame, 
std::unique_ptr<SwParaPortion> xNew)
-    : SwCacheObj(static_cast<void const *>(pFrame))
-    , m_xLine(std::move(xNew) )
+SwParaPortion *SwTextFrame::EnsurePara()
 {
-}
-
-SwTextLine::~SwTextLine()
-{
-}
-
-void SwTextLine::UpdateCachePos()
-{
-    // note: SwTextFrame lives longer than its SwTextLine, see ~SwTextFrame
-    assert(m_pOwner);
-    const_cast<SwTextFrame *>(static_cast<SwTextFrame const 
*>(m_pOwner))->SetCacheIdx(GetCachePos());
-}
-
-SwCacheObj *SwTextLineAccess::NewObj()
-{
-    return new SwTextLine( static_cast<SwTextFrame const *>(m_pOwner) );
-}
-
-SwParaPortion *SwTextLineAccess::GetPara()
-{
-    SwTextLine *pRet;
-    if ( m_pObj )
-        pRet = static_cast<SwTextLine*>(m_pObj);
-    else
-    {
-        pRet = static_cast<SwTextLine*>(Get(false));
-        const_cast<SwTextFrame *>(static_cast<SwTextFrame const 
*>(m_pOwner))->SetCacheIdx( pRet->GetCachePos() );
-    }
-    if ( !pRet->GetPara() )
-        pRet->SetPara(std::make_unique<SwParaPortion>());
-    return pRet->GetPara();
-}
-
-SwTextLineAccess::SwTextLineAccess( const SwTextFrame *pOwn ) :
-    SwCacheAccess( *SwTextFrame::GetTextCache(), pOwn, pOwn->GetCacheIdx() )
-{
-}
-
-bool SwTextLineAccess::IsAvailable() const
-{
-    return m_pObj && static_cast<SwTextLine*>(m_pObj)->GetPara();
-}
-
-bool SwTextFrame::HasPara_() const
-{
-    SwTextLine *pTextLine = 
static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
-                                            Get( this, GetCacheIdx(), false ));
-    if ( pTextLine )
-    {
-        if ( pTextLine->GetPara() )
-            return true;
-    }
-    else
-        const_cast<SwTextFrame*>(this)->mnCacheIndex = USHRT_MAX;
-
-    return false;
-}
-
-SwParaPortion *SwTextFrame::GetPara()
-{
-    if ( GetCacheIdx() != USHRT_MAX )
+    if (!m_xParaPortion)
     {
-        SwTextLine *pLine = 
static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
-                                        Get( this, GetCacheIdx(), false ));
-        if ( pLine )
-            return pLine->GetPara();
-        else
-            mnCacheIndex = USHRT_MAX;
+        m_xParaPortion = std::make_shared<SwParaPortion>();
     }
-    return nullptr;
+    return m_xParaPortion.get();
 }
 
 void SwTextFrame::ClearPara()
 {
     OSL_ENSURE( !IsLocked(), "+SwTextFrame::ClearPara: this is locked." );
-    if ( !IsLocked() && GetCacheIdx() != USHRT_MAX )
+    if ( !IsLocked() && m_xParaPortion )
     {
-        SwTextLine *pTextLine = 
static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
-                                        Get( this, GetCacheIdx(), false ));
-        if ( pTextLine )
-        {
-            pTextLine->SetPara(nullptr);
-        }
-        else
-            mnCacheIndex = USHRT_MAX;
+        m_xParaPortion.reset();
     }
 }
 
 void SwTextFrame::RemoveFromCache()
 {
-    if (GetCacheIdx() != USHRT_MAX)
-    {
-        s_pTextCache->Delete(this, GetCacheIdx());
-        SetCacheIdx(USHRT_MAX);
-    }
+    m_xParaPortion.reset();
 }
 
-std::unique_ptr<SwParaPortion> 
SwTextFrame::SetPara(std::unique_ptr<SwParaPortion> xNew)
+std::shared_ptr<SwParaPortion> 
SwTextFrame::SetPara(std::shared_ptr<SwParaPortion> xNew)
 {
-    std::unique_ptr<SwParaPortion> xOld;
+    std::shared_ptr<SwParaPortion> xOld;
 
-    if ( GetCacheIdx() != USHRT_MAX )
-    {
-        // Only change the information, the CacheObj stays there
-        SwTextLine *pTextLine = 
static_cast<SwTextLine*>(SwTextFrame::GetTextCache()->
-                                        Get( this, GetCacheIdx(), false ));
-        if ( pTextLine )
-        {
-            return pTextLine->SetPara(std::move(xNew));
-        }
-        else
-        {
-            mnCacheIndex = USHRT_MAX;
-        }
-    }
+    if ( m_xParaPortion )
+        xOld = std::move(m_xParaPortion);
 
     if (xNew)
-    {
-        // Insert a new one
-        SwTextLine *pTextLine = new SwTextLine(this, std::move(xNew));
-        if (SwTextFrame::GetTextCache()->Insert(pTextLine, false))
-            mnCacheIndex = pTextLine->GetCachePos();
-        else
-        {
-            OSL_FAIL("+SetPara: InsertCache failed, Losing SwParaPortion.");
-        }
-    }
+        m_xParaPortion = std::move(xNew);
 
     return xOld;
 }
 
-/** Prevent the SwParaPortions of the *visible* paragraphs from being deleted;
-    they would just be recreated on the next paint.
-
-    Heuristic: 100 per view are visible
-
-    If the cache is too small, enlarge it to ensure there are sufficient free
-    entries for the layout so it doesn't have to throw away a node's
-    SwParaPortion when it starts formatting the next node.
-*/
-SwSaveSetLRUOfst::SwSaveSetLRUOfst()
-{
-    sal_uInt16 nVisibleShells(0);
-    for (auto pView = SfxViewShell::GetFirst(true, checkSfxViewShell<SwView>);
-         pView != nullptr;
-         pView = SfxViewShell::GetNext(*pView, true, 
checkSfxViewShell<SwView>))
-    {
-        // Apparently we are not interested here what document pView is for, 
but only in the
-        // total number of shells in the process?
-        ++nVisibleShells;
-    }
-
-    sal_uInt16 const nPreserved(100 * nVisibleShells);
-    SwCache & rCache(*SwTextFrame::GetTextCache());
-    if (rCache.GetCurMax() < nPreserved + 250)
-    {
-        rCache.IncreaseMax(nPreserved + 250 - rCache.GetCurMax());
-    }
-    rCache.SetLRUOfst(nPreserved);
-}
-
-SwSaveSetLRUOfst::~SwSaveSetLRUOfst()
-{
-    SwTextFrame::GetTextCache()->ResetLRUOfst();
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtcache.hxx b/sw/source/core/text/txtcache.hxx
deleted file mode 100644
index 68f907de4597..000000000000
--- a/sw/source/core/text/txtcache.hxx
+++ /dev/null
@@ -1,62 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- *   Licensed to the Apache Software Foundation (ASF) under one or more
- *   contributor license agreements. See the NOTICE file distributed
- *   with this work for additional information regarding copyright
- *   ownership. The ASF licenses this file to you under the Apache
- *   License, Version 2.0 (the "License"); you may not use this file
- *   except in compliance with the License. You may obtain a copy of
- *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-
-#pragma once
-
-#include <swcache.hxx>
-#include "porlay.hxx"
-#include <memory>
-
-class SwTextFrame;
-
-class SwTextLine : public SwCacheObj
-{
-    std::unique_ptr<SwParaPortion> m_xLine;
-
-    virtual void UpdateCachePos() override;
-
-public:
-    SwTextLine(SwTextFrame const* pFrame, std::unique_ptr<SwParaPortion> xNew 
= nullptr);
-    virtual ~SwTextLine() override;
-
-    SwParaPortion* GetPara() { return m_xLine.get(); }
-    const SwParaPortion* GetPara() const { return m_xLine.get(); }
-
-    std::unique_ptr<SwParaPortion> SetPara(std::unique_ptr<SwParaPortion> xNew)
-    {
-        std::unique_ptr<SwParaPortion> xOld = std::move(m_xLine);
-        m_xLine = std::move(xNew);
-        return xOld;
-    }
-};
-
-class SwTextLineAccess : public SwCacheAccess
-{
-protected:
-    virtual SwCacheObj* NewObj() override;
-
-public:
-    explicit SwTextLineAccess(const SwTextFrame* pOwner);
-
-    SwParaPortion* GetPara();
-
-    bool IsAvailable() const;
-};
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx
index b44414238863..b097a5ee5ea0 100644
--- a/sw/source/core/text/txtfrm.cxx
+++ b/sw/source/core/text/txtfrm.cxx
@@ -58,7 +58,6 @@
 #include <sectfrm.hxx>
 #include "itrform2.hxx"
 #include "widorp.hxx"
-#include "txtcache.hxx"
 #include <fntcache.hxx>
 #include <SwGrammarMarkUp.hxx>
 #include <lineinfo.hxx>
@@ -775,7 +774,6 @@ SwTextFrame::SwTextFrame(SwTextNode * const pNode, SwFrame* 
pSib,
     , mnOffset( 0 )
     , mnNoHyphOffset( COMPLETE_STRING )
     , mnNoHyphEndZone( 0 )
-    , mnCacheIndex( USHRT_MAX )
     , mbLocked( false )
     , mbWidow( false )
     , mbJustWidow( false )
@@ -1477,11 +1475,8 @@ LanguageType SwTextFrame::GetLangOfChar(TextFrameIndex 
const nIndex,
 
 void SwTextFrame::ResetPreps()
 {
-    if ( GetCacheIdx() != USHRT_MAX )
-    {
-        if (SwParaPortion *pPara = GetPara())
-            pPara->ResetPreps();
-    }
+    if ( m_xParaPortion )
+        m_xParaPortion->ResetPreps();
 }
 
 static auto FindCellFrame(SwFrame const* pLower) -> SwLayoutFrame const*
@@ -3051,9 +3046,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const 
void* pVoid,
         return bParaPossiblyInvalid;
     }
 
-    // Get object from cache while locking
-    SwTextLineAccess aAccess( this );
-    SwParaPortion *pPara = aAccess.GetPara();
+    SwParaPortion *pPara = EnsurePara();
 
     switch( ePrep )
     {
@@ -3238,7 +3231,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const 
void* pVoid,
                             if (bRelaxed)
                             {
                                 // It's possible that pPara was deleted above; 
retrieve it again
-                                pPara = aAccess.GetPara();
+                                pPara = EnsurePara();
                             }
                         }
                     }
@@ -3273,7 +3266,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const 
void* pVoid,
                 if (bParaPossiblyInvalid)
                 {
                     // It's possible that pPara was deleted above; retrieve it 
again
-                    pPara = aAccess.GetPara();
+                    pPara = EnsurePara();
                 }
 
             }
@@ -3287,7 +3280,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const 
void* pVoid,
 
                 // It's possible that pPara was deleted above; retrieve it 
again
                 bParaPossiblyInvalid = true;
-                pPara = aAccess.GetPara();
+                pPara = EnsurePara();
 
                 InvalidateSize();
                 InvalidatePrt_();
@@ -3387,7 +3380,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const 
void* pVoid,
 class SwTestFormat
 {
     SwTextFrame *pFrame;
-    std::unique_ptr<SwParaPortion> xOldPara;
+    std::shared_ptr<SwParaPortion> xOldPara;
     SwRect aOldFrame, aOldPrt;
 public:
     SwTestFormat( SwTextFrame* pTextFrame, const SwFrame* pPrv, SwTwips 
nMaxHeight );
@@ -3439,7 +3432,7 @@ SwTestFormat::SwTestFormat( SwTextFrame* pTextFrame, 
const SwFrame* pPre, SwTwip
         aRectFnSet.SetWidth( aPrt, aRectFnSet.GetWidth(pFrame->getFrameArea()) 
- ( rAttrs.CalcLeft( pFrame ) + rAttrs.CalcRight( pFrame ) ) );
     }
 
-    xOldPara = pFrame->SetPara(std::make_unique<SwParaPortion>());
+    xOldPara = pFrame->SetPara(std::make_shared<SwParaPortion>());
     OSL_ENSURE( ! pFrame->IsSwapped(), "A frame is swapped before Format_" );
 
     if ( pFrame->IsVertical() )
@@ -3666,7 +3659,7 @@ SwTwips SwTextFrame::CalcFitToContent()
         return getFramePrintArea().Width();
 
     //Swap old para for a dummy
-    std::unique_ptr<SwParaPortion> xOldPara = 
SetPara(std::make_unique<SwParaPortion>());
+    std::shared_ptr<SwParaPortion> xOldPara = 
SetPara(std::make_unique<SwParaPortion>());
     const SwPageFrame* pPage = FindPageFrame();
 
     const Point   aOldFramePos   = getFrameArea().Pos();
@@ -3771,7 +3764,7 @@ void SwTextFrame::CalcAdditionalFirstLineOffset()
         return;
 
     // keep current paragraph portion and apply dummy paragraph portion
-    std::unique_ptr<SwParaPortion> xOldPara = 
SetPara(std::make_unique<SwParaPortion>());
+    std::shared_ptr<SwParaPortion> xOldPara = 
SetPara(std::make_shared<SwParaPortion>());
 
     // lock paragraph
     TextFrameLockGuard aLock( this );
diff --git a/sw/source/core/text/txtinit.cxx b/sw/source/core/text/txtinit.cxx
index 2b8bb2e95d21..98d85f9ebe8b 100644
--- a/sw/source/core/text/txtinit.cxx
+++ b/sw/source/core/text/txtinit.cxx
@@ -26,7 +26,6 @@
 #include <txtfly.hxx>
 #include <dbg_lay.hxx>
 
-SwCache *SwTextFrame::s_pTextCache = nullptr;
 SwContourCache *pContourCache = nullptr;
 SwDropCapCache *pDropCapCache = nullptr;
 
@@ -38,19 +37,12 @@ void TextInit_()
 {
     pFntCache = new SwFntCache; // Cache for SwSubFont -> SwFntObj = { Font 
aFont, Font* pScrFont, Font* pPrtFont, OutputDevice* pPrinter, ... }
     pSwFontCache = new SwFontCache; // Cache for SwTextFormatColl -> SwFontObj 
= { SwFont aSwFont, SfxPoolItem* pDefaultArray }
-    SwCache *pTextCache = new SwCache( 250 // Cache for SwTextFrame -> 
SwTextLine = { SwParaPortion* pLine }
-#ifdef DBG_UTIL
-    , "static SwTextFrame::s_pTextCache"_ostr
-#endif
-    );
-    SwTextFrame::SetTextCache( pTextCache );
     PROTOCOL_INIT
 }
 
 void TextFinit()
 {
     PROTOCOL_STOP
-    delete SwTextFrame::GetTextCache();
     delete pSwFontCache;
     delete pFntCache;
     delete pContourCache;
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index 52738e2f1c48..c00ed44bbf5b 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -853,8 +853,6 @@ void SwViewShell::LayoutIdle()
 #endif
 
     {
-        // Preserve top of the text frame cache.
-        SwSaveSetLRUOfst aSaveLRU;
         // #125243# there are lots of stacktraces indicating that Imp() 
returns NULL
         // this SwViewShell seems to be invalid - but it's not clear why
         // this return is only a workaround!
@@ -1232,9 +1230,6 @@ void SwViewShell::CalcLayout()
     CurrShell aCurr( this );
     SwWait aWait( *GetDoc()->GetDocShell(), true );
 
-    // Preserve top of the text frame cache.
-    SwSaveSetLRUOfst aSaveLRU;
-
     //switch on Progress when none is running yet.
     const bool bEndProgress = SfxProgress::GetActiveProgress( 
GetDoc()->GetDocShell() ) == nullptr;
     if ( bEndProgress )
diff --git a/sw/source/core/view/vnew.cxx b/sw/source/core/view/vnew.cxx
index 024a0f163e80..f85d5c6c94c1 100644
--- a/sw/source/core/view/vnew.cxx
+++ b/sw/source/core/view/vnew.cxx
@@ -173,9 +173,6 @@ void SwViewShell::Init( const SwViewOption *pNewOpt, 
tools::Long const nFlags)
         mxDoc->getIDocumentState().ResetModified();
     }
 
-    // extend format cache.
-    if ( SwTextFrame::GetTextCache()->GetCurMax() < 2550 )
-        SwTextFrame::GetTextCache()->IncreaseMax( 100 );
     if( mpOpt->IsGridVisible() || getIDocumentDrawModelAccess().GetDrawModel() 
)
         Imp()->MakeDrawView();
 
@@ -289,10 +286,6 @@ SwViewShell::~SwViewShell()
 
         mpOpt.reset();
 
-        // resize format cache.
-        if ( SwTextFrame::GetTextCache()->GetCurMax() > 250 )
-            SwTextFrame::GetTextCache()->DecreaseMax( 100 );
-
         // Remove from PaintQueue if necessary
         SwPaintQueue::Remove( this );
 

Reply via email to