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> (cherry picked from commit 92b13ad1f1a87393cf66a35694f3e542db57f150) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/152874 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
committed by
Noel Grandin
parent
d27aac755a
commit
447a4bcac0
@@ -189,6 +189,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 \
|
||||
|
||||
@@ -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;
|
||||
|
||||
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);
|
||||
};
|
||||
@@ -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 );
|
||||
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <sheetdatabuffer.hxx>
|
||||
#include <patterncache.hxx>
|
||||
|
||||
#include <algorithm>
|
||||
#include <com/sun/star/sheet/XArrayFormulaTokens.hpp>
|
||||
@@ -481,6 +482,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 );
|
||||
@@ -510,7 +513,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())
|
||||
{
|
||||
|
||||
@@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#include <stylesbuffer.hxx>
|
||||
#include <patterncache.hxx>
|
||||
|
||||
#include <com/sun/star/awt/FontDescriptor.hpp>
|
||||
#include <com/sun/star/awt/FontFamily.hpp>
|
||||
@@ -2065,13 +2066,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 );
|
||||
@@ -2096,19 +2100,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)
|
||||
@@ -2134,6 +2139,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))
|
||||
|
||||
Reference in New Issue
Block a user