From e1268721d4266ed1254da99581a7c2c3dfb72ba6 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 18 Apr 2024 10:50:38 +0200 Subject: [PATCH] tdf#160706 speed up loading conditional formatting rule in XLS (3) the comment when calling MakeCellStyleSheet does not match the implementation, so make the implementation match the comment. i.e. if there is an existing stylesheet with that name, just return it. Reduces load time for me from 47s to 33s Change-Id: If1bd08baf8515933b87c075d9eef04bc0a125357 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166241 Tested-by: Jenkins Reviewed-by: Noel Grandin --- sc/source/filter/excel/xicontent.cxx | 2 +- sc/source/filter/ftools/ftools.cxx | 9 +++++++-- sc/source/filter/inc/ftools.hxx | 7 +++---- sc/source/filter/oox/stylesbuffer.cxx | 4 ++-- 4 files changed, 13 insertions(+), 9 deletions(-) diff --git a/sc/source/filter/excel/xicontent.cxx b/sc/source/filter/excel/xicontent.cxx index a2862f7b6988..8701b3c69204 100644 --- a/sc/source/filter/excel/xicontent.cxx +++ b/sc/source/filter/excel/xicontent.cxx @@ -576,7 +576,7 @@ void XclImpCondFormat::ReadCF( XclImpStream& rStrm ) // *** create style sheet *** OUString aStyleName( XclTools::GetCondFormatStyleName( GetCurrScTab(), mnFormatIndex, mnCondIndex ) ); - SfxItemSet& rStyleItemSet = ScfTools::MakeCellStyleSheet( GetStyleSheetPool(), aStyleName, true ).GetItemSet(); + SfxItemSet& rStyleItemSet = ScfTools::MakeCellStyleSheet( GetStyleSheetPool(), aStyleName ).GetItemSet(); const XclImpPalette& rPalette = GetPalette(); diff --git a/sc/source/filter/ftools/ftools.cxx b/sc/source/filter/ftools/ftools.cxx index bf2b784a994b..1ce82e5dd1d8 100644 --- a/sc/source/filter/ftools/ftools.cxx +++ b/sc/source/filter/ftools/ftools.cxx @@ -254,9 +254,14 @@ ScStyleSheet& lclMakeStyleSheet( ScStyleSheetPool& rPool, const OUString& rStyle } // namespace -ScStyleSheet& ScfTools::MakeCellStyleSheet( ScStyleSheetPool& rPool, const OUString& rStyleName, bool bForceName ) +ScStyleSheet& ScfTools::MakeCellStyleSheet( ScStyleSheetPool& rPool, const OUString& rStyleName ) { - return lclMakeStyleSheet( rPool, rStyleName, SfxStyleFamily::Para, bForceName ); + SfxStyleSheetBase* pOldStyleSheet = rPool.Find( rStyleName, SfxStyleFamily::Para ); + if( pOldStyleSheet ) + return static_cast< ScStyleSheet& >(*pOldStyleSheet); + + // create new style sheet + return static_cast< ScStyleSheet& >( rPool.Make( rStyleName, SfxStyleFamily::Para, SfxStyleSearchBits::UserDefined ) ); } ScStyleSheet& ScfTools::MakePageStyleSheet( ScStyleSheetPool& rPool, const OUString& rStyleName, bool bForceName ) diff --git a/sc/source/filter/inc/ftools.hxx b/sc/source/filter/inc/ftools.hxx index 7e8a07bce8c8..0fdb90cc26ae 100644 --- a/sc/source/filter/inc/ftools.hxx +++ b/sc/source/filter/inc/ftools.hxx @@ -193,12 +193,11 @@ public: // *** style sheet handling *** ----------------------------------------------- /** Creates and returns a cell style sheet and inserts it into the pool. - @descr If the style sheet is already in the pool, another unused style name is used. - @param bForceName Controls behaviour, if the style already exists: - true = Old existing style will be renamed; false = New style gets another name. */ + @descr If the style sheet is already in the pool, return the existing style. + */ static ScStyleSheet& MakeCellStyleSheet( ScStyleSheetPool& rPool, - const OUString& rStyleName, bool bForceName ); + const OUString& rStyleName ); /** Creates and returns a page style sheet and inserts it into the pool. @descr If the style sheet is already in the pool, another unused style name is used. @param bForceName Controls behaviour, if the style already exists: diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index 234d0365bdec..76245a6980a3 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -3005,7 +3005,7 @@ OUString StylesBuffer::createDxfStyle( sal_Int32 nDxfId ) const // Create a cell style. This may overwrite an existing style if // one with the same name exists. ScStyleSheet& rStyleSheet = ScfTools::MakeCellStyleSheet( - *getScDocument().GetStyleSheetPool(), rStyleName, true); + *getScDocument().GetStyleSheetPool(), rStyleName); rStyleSheet.ResetParent(); SfxItemSet& rStyleItemSet = @@ -3033,7 +3033,7 @@ OUString StylesBuffer::createExtDxfStyle( sal_Int32 nDxfId ) const // Create a cell style. This may overwrite an existing style if // one with the same name exists. ScStyleSheet& rStyleSheet = ScfTools::MakeCellStyleSheet( - *getScDocument().GetStyleSheetPool(), rStyleName, true); + *getScDocument().GetStyleSheetPool(), rStyleName); rStyleSheet.ResetParent(); SfxItemSet& rStyleItemSet =