diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2023-06-07 11:34:56 +0530 |
---|---|---|
committer | Caolán McNamara <caolan.mcnamara@collabora.com> | 2023-06-28 13:05:11 +0200 |
commit | 64dbb50e028e56c224a55affbc17277da40b659e (patch) | |
tree | 4937cac4a36af03bb833c41bf8ae828351e38dd7 | |
parent | tdf#153466 PPTX import: fix "Custom position/size" background image (diff) | |
download | core-64dbb50e028e56c224a55affbc17277da40b659e.tar.gz core-64dbb50e028e56c224a55affbc17277da40b659e.zip |
sc: perf: speedup sheets with lots of repetitive...
row styles using a small cache of already allocated patterns that are
tied to extended format id and number format id.
Change-Id: I3136aef9a034635924f7b7b6d2432f9ae5c2bd15
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152692
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Andras Timar <andras.timar@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/153588
Reviewed-by: Caolán McNamara <caolan.mcnamara@collabora.com>
-rw-r--r-- | sc/Library_scfilt.mk | 1 | ||||
-rw-r--r-- | sc/source/filter/inc/patterncache.hxx | 46 | ||||
-rw-r--r-- | sc/source/filter/inc/stylesbuffer.hxx | 5 | ||||
-rw-r--r-- | sc/source/filter/oox/patterncache.cxx | 52 | ||||
-rw-r--r-- | sc/source/filter/oox/sheetdatabuffer.cxx | 6 | ||||
-rw-r--r-- | sc/source/filter/oox/stylesbuffer.cxx | 23 |
6 files changed, 124 insertions, 9 deletions
diff --git a/sc/Library_scfilt.mk b/sc/Library_scfilt.mk index eff7cca485e4..4614e8889ba1 100644 --- a/sc/Library_scfilt.mk +++ b/sc/Library_scfilt.mk @@ -188,6 +188,7 @@ $(eval $(call gb_Library_add_exception_objects,scfilt,\ sc/source/filter/oox/numberformatsbuffer \ sc/source/filter/oox/ooxformulaparser \ sc/source/filter/oox/pagesettings \ + sc/source/filter/oox/patterncache \ sc/source/filter/oox/pivotcachebuffer \ sc/source/filter/oox/pivotcachefragment \ sc/source/filter/oox/pivottablebuffer \ diff --git a/sc/source/filter/inc/patterncache.hxx b/sc/source/filter/inc/patterncache.hxx new file mode 100644 index 000000000000..3962dccc37da --- /dev/null +++ b/sc/source/filter/inc/patterncache.hxx @@ -0,0 +1,46 @@ +/* -*- 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 <sal/types.h> + +class ScPatternAttr; + +static constexpr sal_Int32 nPatternCacheSize = 16; +class ScPatternCache +{ + struct Entry + { + sal_Int32 nXfId; + sal_Int32 nNumFmtId; + ScPatternAttr* pPattern; + + Entry(); + }; + + Entry maEntries[nPatternCacheSize]; + sal_Int32 nNextPos; + +public: + ScPatternCache(); + + ScPatternAttr* query(sal_Int32 nXfId, sal_Int32 nNumFmtId) const; + void add(sal_Int32 nXfId, sal_Int32 nNumFmtId, ScPatternAttr* pPattern); +}; diff --git a/sc/source/filter/inc/stylesbuffer.hxx b/sc/source/filter/inc/stylesbuffer.hxx index 4d9e7aeed33d..2cc7590dbcde 100644 --- a/sc/source/filter/inc/stylesbuffer.hxx +++ b/sc/source/filter/inc/stylesbuffer.hxx @@ -35,6 +35,8 @@ #include <attarray.hxx> #include <vector> +class ScPatternCache; + namespace oox { class SequenceInputStream; } namespace oox { class PropertySet; @@ -623,7 +625,8 @@ public: const Alignment& getAlignment() const { return maAlignment; } void applyPatternToAttrList( - AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nForceScNumFmt ); + AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nXfId, + sal_Int32 nForceScNumFmt, ScPatternCache& rCache ); void writeToDoc( ScDocumentImport& rDoc, const ScRange& rRange ); diff --git a/sc/source/filter/oox/patterncache.cxx b/sc/source/filter/oox/patterncache.cxx new file mode 100644 index 000000000000..2431a36fed20 --- /dev/null +++ b/sc/source/filter/oox/patterncache.cxx @@ -0,0 +1,52 @@ +/* -*- 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 . + */ + +#include <patterncache.hxx> + +ScPatternCache::Entry::Entry() + : nXfId(-1) + , nNumFmtId(-1) + , pPattern(nullptr) +{ +} + +ScPatternCache::ScPatternCache() + : nNextPos(0) +{ +} + +ScPatternAttr* ScPatternCache::query(sal_Int32 nXfId, sal_Int32 nNumFmtId) const +{ + for (const auto& entry : maEntries) + { + if (entry.nXfId == nXfId && entry.nNumFmtId == nNumFmtId) + return entry.pPattern; + } + + return nullptr; +} + +void ScPatternCache::add(sal_Int32 nXfId, sal_Int32 nNumFmtId, ScPatternAttr* pPattern) +{ + Entry& rEntry = maEntries[nNextPos]; + nNextPos = ((nNextPos + 1) % nPatternCacheSize); + rEntry.nXfId = nXfId; + rEntry.nNumFmtId = nNumFmtId; + rEntry.pPattern = pPattern; +} diff --git a/sc/source/filter/oox/sheetdatabuffer.cxx b/sc/source/filter/oox/sheetdatabuffer.cxx index 422220968812..ff1828b5591f 100644 --- a/sc/source/filter/oox/sheetdatabuffer.cxx +++ b/sc/source/filter/oox/sheetdatabuffer.cxx @@ -18,6 +18,7 @@ */ #include <sheetdatabuffer.hxx> +#include <patterncache.hxx> #include <algorithm> #include <com/sun/star/sheet/XArrayFormulaTokens.hpp> @@ -476,6 +477,8 @@ void SheetDataBuffer::finalizeImport() ScDocumentImport::Attrs aPendingAttrParam; SCCOL pendingColStart = -1; SCCOL pendingColEnd = -1; + ScPatternCache aPatternCache; + for ( const auto& [rCol, rRowStyles] : maStylesPerColumn ) { SCCOL nScCol = static_cast< SCCOL >( rCol ); @@ -505,7 +508,8 @@ void SheetDataBuffer::finalizeImport() Xf* pXf = rStyles.getCellXf( rRowStyle.mnNumFmt.first ).get(); if ( pXf ) - pXf->applyPatternToAttrList( aAttrs, rRowStyle.mnStartRow, rRowStyle.mnEndRow, rRowStyle.mnNumFmt.second ); + pXf->applyPatternToAttrList( aAttrs, rRowStyle.mnStartRow, rRowStyle.mnEndRow, + rRowStyle.mnNumFmt.first, rRowStyle.mnNumFmt.second, aPatternCache ); } if (aAttrs.maAttrs.empty() || aAttrs.maAttrs.back().nEndRow != rDoc.MaxRow()) { diff --git a/sc/source/filter/oox/stylesbuffer.cxx b/sc/source/filter/oox/stylesbuffer.cxx index 9edfb0081b29..2089e48f037b 100644 --- a/sc/source/filter/oox/stylesbuffer.cxx +++ b/sc/source/filter/oox/stylesbuffer.cxx @@ -18,6 +18,7 @@ */ #include <stylesbuffer.hxx> +#include <patterncache.hxx> #include <com/sun/star/awt/FontDescriptor.hpp> #include <com/sun/star/awt/FontFamily.hpp> @@ -2040,13 +2041,16 @@ FontRef Xf::getFont() const return getStyles().getFont( maModel.mnFontId ); } -void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nNumFmtId ) +void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal_Int32 nXfId, sal_Int32 nNumFmtId, ScPatternCache& rCache ) { - createPattern(); - ScPatternAttr& rPat = *mpPattern; + ScPatternAttr* pCachedPattern = rCache.query(nXfId, nNumFmtId); + if (!pCachedPattern) + createPattern(); + + ScPatternAttr& rPat = pCachedPattern ? *pCachedPattern : *mpPattern; ScDocumentImport& rDocImport = getDocImport(); ScDocument& rDoc = getScDocument(); - if ( isCellXf() ) + if ( !pCachedPattern && isCellXf() ) { StylesBuffer& rStyles = getStyles(); rStyles.createCellStyle( maModel.mnStyleXfId ); @@ -2071,19 +2075,20 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal } } } - if ( nNumFmtId >= 0 ) + if ( !pCachedPattern && nNumFmtId >= 0 ) { ScPatternAttr aNumPat(rDoc.GetPool()); mnScNumFmt = getStyles().writeNumFmtToItemSet( aNumPat.GetItemSet(), nNumFmtId, false ); rPat.GetItemSet().Put(aNumPat.GetItemSet()); } - if (!rDocImport.isLatinScript(mnScNumFmt)) + if (!pCachedPattern && !rDocImport.isLatinScript(mnScNumFmt)) rAttrs.mbLatinNumFmtOnly = false; - if (!rPat.GetStyleName()) + if (!pCachedPattern && !rPat.GetStyleName()) return; + // Check for a gap between the last entry and this one. bool bHasGap = false; if (rAttrs.maAttrs.empty() && nRow1 > 0) @@ -2109,6 +2114,10 @@ void Xf::applyPatternToAttrList( AttrList& rAttrs, SCROW nRow1, SCROW nRow2, sal ScAttrEntry aEntry; aEntry.nEndRow = nRow2; aEntry.pPattern = &rDoc.GetPool()->Put(rPat); + // Put the allocated pattern to cache + if (!pCachedPattern) + rCache.add(nXfId, nNumFmtId, const_cast<ScPatternAttr*>(aEntry.pPattern)); + rAttrs.maAttrs.push_back(aEntry); if (!rDocImport.isLatinScript(*aEntry.pPattern)) |