sc/source/filter/inc/richstring.hxx            |   15 ++++++-------
 sc/source/filter/oox/commentsbuffer.cxx        |    4 +--
 sc/source/filter/oox/commentsfragment.cxx      |    2 -
 sc/source/filter/oox/revisionfragment.cxx      |    2 -
 sc/source/filter/oox/richstring.cxx            |   27 +++++++++++--------------
 sc/source/filter/oox/richstringcontext.cxx     |    2 -
 sc/source/filter/oox/sharedstringsbuffer.cxx   |    5 ++--
 sc/source/filter/oox/sharedstringsfragment.cxx |    2 -
 sc/source/filter/oox/sheetdatacontext.cxx      |   16 +++++++-------
 9 files changed, 36 insertions(+), 39 deletions(-)

New commits:
commit be198c259eb9f9097061be0a1b61359cd039369d
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Tue Jul 5 14:51:32 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Mon Jul 11 11:59:42 2022 +0200

    compact the RichString class
    
    Which reduces peak memory load from 495M to 455M when loading
    a large spreadsheet
    
    Change-Id: Iad78524bedf3db193820be2d507652abde59d67c
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136827
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>
    (cherry picked from commit 9047c22d05df16b5488acfcc70c1b6f4dc8dd13b)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/136772
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>

diff --git a/sc/source/filter/inc/richstring.hxx 
b/sc/source/filter/inc/richstring.hxx
index fe0d0f2f527a..1e3cf921b326 100644
--- a/sc/source/filter/inc/richstring.hxx
+++ b/sc/source/filter/inc/richstring.hxx
@@ -144,10 +144,10 @@ private:
 };
 
 /** Contains text data and positioning information for a phonetic text 
portion. */
-class RichStringPhonetic : public WorkbookHelper
+class RichStringPhonetic
 {
 public:
-    explicit            RichStringPhonetic( const WorkbookHelper& rHelper );
+    RichStringPhonetic();
 
     /** Sets text data for this phonetic portion. */
     void                setText( const OUString& rText );
@@ -203,10 +203,9 @@ private:
 };
 
 /** Contains string data and a list of formatting runs for a rich formatted 
string. */
-class RichString : public WorkbookHelper
+class RichString
 {
 public:
-    explicit            RichString( const WorkbookHelper& rHelper );
 
     /** Appends and returns an index of a portion object for a plain string (t 
element). */
     sal_Int32 importText();
@@ -215,13 +214,13 @@ public:
     /** Appends and returns a phonetic text object for a new phonetic run (rPh 
element). */
     RichStringPhoneticRef importPhoneticRun( const AttributeList& rAttribs );
     /** Imports phonetic settings from the rPhoneticPr element. */
-    void                importPhoneticPr( const AttributeList& rAttribs );
+    void                importPhoneticPr( const AttributeList& rAttribs, const 
WorkbookHelper& rHelper );
 
     /** Imports a Unicode rich-string from the passed record stream. */
-    void                importString( SequenceInputStream& rStrm, bool bRich );
+    void                importString( SequenceInputStream& rStrm, bool bRich, 
const WorkbookHelper& rHelper );
 
     /** Final processing after import of all strings. */
-    void                finalizeImport();
+    void                finalizeImport(const WorkbookHelper& rHelper);
 
     /** Tries to extract a plain string from this object. Returns the string,
         if there is only one unformatted portion. */
@@ -252,7 +251,7 @@ private:
     typedef RefVector< RichStringPhonetic > PhoneticVector;
 
     std::vector<RichStringPortion>  maTextPortions; /// String portions with 
font data.
-    PhoneticSettings    maPhonSettings; /// Phonetic settings for this string.
+    std::unique_ptr<PhoneticSettings> mxPhonSettings; /// Phonetic settings 
for this string.
     PhoneticVector      maPhonPortions; /// Phonetic text portions.
 };
 
diff --git a/sc/source/filter/oox/commentsbuffer.cxx 
b/sc/source/filter/oox/commentsbuffer.cxx
index b4e6c7f48cb1..7dbd5c942e30 100644
--- a/sc/source/filter/oox/commentsbuffer.cxx
+++ b/sc/source/filter/oox/commentsbuffer.cxx
@@ -141,7 +141,7 @@ void Comment::importComment( SequenceInputStream& rStrm )
 
 RichStringRef const & Comment::createText()
 {
-    maModel.mxText = std::make_shared<RichString>( *this );
+    maModel.mxText = std::make_shared<RichString>();
     return maModel.mxText;
 }
 
@@ -196,7 +196,7 @@ void Comment::finalizeImport()
             pDocShell->GetDocFunc().ShowNote( maModel.maRange.aStart, bVisible 
);
 
         // insert text and convert text formatting
-        maModel.mxText->finalizeImport();
+        maModel.mxText->finalizeImport(*this);
         Reference< XText > xAnnoText( xAnnoShape, UNO_QUERY_THROW );
         Reference< css::document::XActionLockable > xAnnoLock( xAnnoShape, 
UNO_QUERY_THROW );
         xAnnoLock->addActionLock();
diff --git a/sc/source/filter/oox/commentsfragment.cxx 
b/sc/source/filter/oox/commentsfragment.cxx
index 0d6a8b27a870..a5d1da8dacc8 100644
--- a/sc/source/filter/oox/commentsfragment.cxx
+++ b/sc/source/filter/oox/commentsfragment.cxx
@@ -100,7 +100,7 @@ ContextHandlerRef CommentsFragment::onCreateRecordContext( 
sal_Int32 nRecId, Seq
         break;
         case BIFF12_ID_COMMENT:
             if( (nRecId == BIFF12_ID_COMMENTTEXT) && mxComment )
-                mxComment->createText()->importString( rStrm, true );
+                mxComment->createText()->importString( rStrm, true, *this );
         break;
     }
     return nullptr;
diff --git a/sc/source/filter/oox/revisionfragment.cxx 
b/sc/source/filter/oox/revisionfragment.cxx
index f6fee91c4051..a5a57a6d314c 100644
--- a/sc/source/filter/oox/revisionfragment.cxx
+++ b/sc/source/filter/oox/revisionfragment.cxx
@@ -74,7 +74,7 @@ protected:
     {
         if (nElement == XLS_TOKEN(is))
         {
-            mxRichString = std::make_shared<RichString>(*this);
+            mxRichString = std::make_shared<RichString>();
             return new RichStringContext(*this, mxRichString);
         }
 
diff --git a/sc/source/filter/oox/richstring.cxx 
b/sc/source/filter/oox/richstring.cxx
index bc040cdceeb5..8ac24b0ccd01 100644
--- a/sc/source/filter/oox/richstring.cxx
+++ b/sc/source/filter/oox/richstring.cxx
@@ -340,8 +340,7 @@ void PhoneticSettings::importStringData( 
SequenceInputStream& rStrm )
     maModel.setBiffData( extractValue< sal_Int32 >( nFlags, 0, 2 ), 
extractValue< sal_Int32 >( nFlags, 2, 2 ) );
 }
 
-RichStringPhonetic::RichStringPhonetic( const WorkbookHelper& rHelper ) :
-    WorkbookHelper( rHelper ),
+RichStringPhonetic::RichStringPhonetic() :
     mnBasePos( -1 ),
     mnBaseEnd( -1 )
 {
@@ -404,12 +403,6 @@ void PhoneticPortionModelList::importPortions( 
SequenceInputStream& rStrm )
     }
 }
 
-RichString::RichString( const WorkbookHelper& rHelper ) :
-    WorkbookHelper( rHelper ),
-    maPhonSettings( rHelper )
-{
-}
-
 sal_Int32 RichString::importText()
 {
     return createPortion();
@@ -427,12 +420,14 @@ RichStringPhoneticRef RichString::importPhoneticRun( 
const AttributeList& rAttri
     return xPhonetic;
 }
 
-void RichString::importPhoneticPr( const AttributeList& rAttribs )
+void RichString::importPhoneticPr( const AttributeList& rAttribs, const 
WorkbookHelper& rHelper )
 {
-    maPhonSettings.importPhoneticPr( rAttribs );
+    if (!mxPhonSettings)
+        mxPhonSettings.reset(new PhoneticSettings(rHelper));
+    mxPhonSettings->importPhoneticPr( rAttribs );
 }
 
-void RichString::importString( SequenceInputStream& rStrm, bool bRich )
+void RichString::importString( SequenceInputStream& rStrm, bool bRich, const 
WorkbookHelper& rHelper )
 {
     sal_uInt8 nFlags = bRich ? rStrm.readuInt8() : 0;
     OUString aBaseText = BiffHelper::readString( rStrm );
@@ -453,15 +448,17 @@ void RichString::importString( SequenceInputStream& 
rStrm, bool bRich )
         OUString aPhoneticText = BiffHelper::readString( rStrm );
         PhoneticPortionModelList aPortions;
         aPortions.importPortions( rStrm );
-        maPhonSettings.importStringData( rStrm );
+        if (!mxPhonSettings)
+            mxPhonSettings.reset(new PhoneticSettings(rHelper));
+        mxPhonSettings->importStringData( rStrm );
         createPhoneticPortions( aPhoneticText, aPortions, 
aBaseText.getLength() );
     }
 }
 
-void RichString::finalizeImport()
+void RichString::finalizeImport(const WorkbookHelper& rHelper)
 {
     for (RichStringPortion& rPortion : maTextPortions)
-        rPortion.finalizeImport( *this );
+        rPortion.finalizeImport( rHelper );
 }
 
 bool RichString::extractPlainString( OUString& orString, const oox::xls::Font* 
pFirstPortionFont ) const
@@ -533,7 +530,7 @@ sal_Int32 RichString::createPortion()
 
 RichStringPhoneticRef RichString::createPhonetic()
 {
-    RichStringPhoneticRef xPhonetic = std::make_shared<RichStringPhonetic>( 
*this );
+    RichStringPhoneticRef xPhonetic = std::make_shared<RichStringPhonetic>();
     maPhonPortions.push_back( xPhonetic );
     return xPhonetic;
 }
diff --git a/sc/source/filter/oox/richstringcontext.cxx 
b/sc/source/filter/oox/richstringcontext.cxx
index 7f899f23bb27..280ac293a390 100644
--- a/sc/source/filter/oox/richstringcontext.cxx
+++ b/sc/source/filter/oox/richstringcontext.cxx
@@ -42,7 +42,7 @@ ContextHandlerRef RichStringContext::onCreateContext( 
sal_Int32 nElement, const
                 mxPhonetic = mxString->importPhoneticRun( rAttribs );
                 return this;
             case XLS_TOKEN( phoneticPr ):
-                mxString->importPhoneticPr( rAttribs );
+                mxString->importPhoneticPr( rAttribs, *this );
             break;
         }
     }
diff --git a/sc/source/filter/oox/sharedstringsbuffer.cxx 
b/sc/source/filter/oox/sharedstringsbuffer.cxx
index 2f1287d7342f..6198c8e1301a 100644
--- a/sc/source/filter/oox/sharedstringsbuffer.cxx
+++ b/sc/source/filter/oox/sharedstringsbuffer.cxx
@@ -28,14 +28,15 @@ SharedStringsBuffer::SharedStringsBuffer( const 
WorkbookHelper& rHelper ) :
 
 RichStringRef SharedStringsBuffer::createRichString()
 {
-    RichStringRef xString = std::make_shared<RichString>( *this );
+    RichStringRef xString = std::make_shared<RichString>();
     maStrings.push_back( xString );
     return xString;
 }
 
 void SharedStringsBuffer::finalizeImport()
 {
-    maStrings.forEachMem( &RichString::finalizeImport );
+    for (auto & rString : maStrings)
+        rString->finalizeImport(*this);
 }
 
 RichStringRef SharedStringsBuffer::getString( sal_Int32 nStringId ) const
diff --git a/sc/source/filter/oox/sharedstringsfragment.cxx 
b/sc/source/filter/oox/sharedstringsfragment.cxx
index a1f10664595d..841d2b1d3a3c 100644
--- a/sc/source/filter/oox/sharedstringsfragment.cxx
+++ b/sc/source/filter/oox/sharedstringsfragment.cxx
@@ -62,7 +62,7 @@ ContextHandlerRef 
SharedStringsFragment::onCreateRecordContext( sal_Int32 nRecId
 
         case BIFF12_ID_SST:
             if( nRecId == BIFF12_ID_SI )
-                getSharedStrings().createRichString()->importString( rStrm, 
true );
+                getSharedStrings().createRichString()->importString( rStrm, 
true, *this );
         break;
     }
     return nullptr;
diff --git a/sc/source/filter/oox/sheetdatacontext.cxx 
b/sc/source/filter/oox/sheetdatacontext.cxx
index 6a038cac8701..2d373548a30f 100644
--- a/sc/source/filter/oox/sheetdatacontext.cxx
+++ b/sc/source/filter/oox/sheetdatacontext.cxx
@@ -92,7 +92,7 @@ ContextHandlerRef SheetDataContext::onCreateContext( 
sal_Int32 nElement, const A
             switch( nElement )
             {
                 case XLS_TOKEN( is ):
-                    mxInlineStr = std::make_shared<RichString>( *this );
+                    mxInlineStr = std::make_shared<RichString>();
                     return new RichStringContext( *this, mxInlineStr );
                 case XLS_TOKEN( v ):
                     return this;    // characters contain cell value
@@ -201,7 +201,7 @@ void SheetDataContext::onEndElement()
     }
     else if( (maCellData.mnCellType == XML_inlineStr) && mxInlineStr )
     {
-        mxInlineStr->finalizeImport();
+        mxInlineStr->finalizeImport(*this);
         mrSheetData.setStringCell( maCellData, mxInlineStr );
     }
     else
@@ -502,9 +502,9 @@ void SheetDataContext::importCellRString( 
SequenceInputStream& rStrm, CellType e
     if( readCellHeader( rStrm, eCellType ) )
     {
         maCellData.mnCellType = XML_inlineStr;
-        RichStringRef xString = std::make_shared<RichString>( *this );
-        xString->importString( rStrm, true );
-        xString->finalizeImport();
+        RichStringRef xString = std::make_shared<RichString>();
+        xString->importString( rStrm, true, *this );
+        xString->finalizeImport( *this );
         mrSheetData.setStringCell( maCellData, xString );
     }
 }
@@ -525,9 +525,9 @@ void SheetDataContext::importCellString( 
SequenceInputStream& rStrm, CellType eC
     {
         maCellData.mnCellType = XML_inlineStr;
         // always import the string, stream will point to formula afterwards, 
if existing
-        RichStringRef xString = std::make_shared<RichString>( *this );
-        xString->importString( rStrm, false );
-        xString->finalizeImport();
+        RichStringRef xString = std::make_shared<RichString>();
+        xString->importString( rStrm, false, *this );
+        xString->finalizeImport( *this );
         if( eCellType == CELLTYPE_FORMULA )
             mrSheetData.setFormulaCell( maCellData, readCellFormula( rStrm ) );
         else

Reply via email to