summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@collabora.com>2022-03-01 15:07:02 +0100
committerLuboš Luňák <l.lunak@collabora.com>2022-03-02 09:27:33 +0100
commit4e279e8c4986ca3de79bea2216c5783cb113a5bb (patch)
treeb47bf258dc3e111681f0772e2ae39b6123f2d93d /sc
parentf8edf0a94e9608d7e7d8ed5fb46036b2ceb71693 (diff)
reuse a vector instead of repeatedly creating it (tdf#95346)
With some documents this actually is a noticeable cost. Change-Id: Ibaf2157eeba83e0c8f78c7ba058771f92bb44e24 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/130795 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/filter/excel/xetable.cxx17
-rw-r--r--sc/source/filter/inc/xetable.hxx1
2 files changed, 14 insertions, 4 deletions
diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index f2ed192c3c40..bf50dd647933 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -1918,7 +1918,7 @@ void XclExpRow::AppendCell( XclExpCellRef const & xCell, bool bIsMergedBase )
InsertCell( xCell, maCellList.GetSize(), bIsMergedBase );
}
-void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, size_t nStartColAllDefault, bool bProgress )
+void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, ScfUInt16Vec& aXFIndexes, size_t nStartColAllDefault, bool bProgress )
{
size_t nPos, nSize;
@@ -1928,7 +1928,11 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, size_t nStartColAll
size_t nColCount = GetMaxPos().Col() + 1;
OSL_ENSURE( rColXFIndexes.size() == nColCount, "XclExpRow::Finalize - wrong column XF index count" );
- ScfUInt16Vec aXFIndexes( nColCount, EXC_XF_NOTFOUND );
+ // The vector should be preset to all items being EXC_XF_NOTFOUND, to avoid repeated allocations
+ // and clearing.
+ assert( aXFIndexes.size() == nColCount );
+ assert( aXFIndexes.front() == EXC_XF_NOTFOUND );
+ assert( aXFIndexes.back() == EXC_XF_NOTFOUND );
for( nPos = 0, nSize = maCellList.GetSize(); nPos < nSize; ++nPos )
{
XclExpCellBase* pCell = maCellList.GetRecord( nPos );
@@ -2084,6 +2088,9 @@ void XclExpRow::Finalize( const ScfUInt16Vec& rColXFIndexes, size_t nStartColAll
else
++nPos;
}
+ // Ensure it's all EXC_XF_NOTFOUND again for next reuse.
+ for( size_t i = 0; i < nStartAllNotFound; ++i )
+ aXFIndexes[ i ] = EXC_XF_NOTFOUND;
// progress bar includes disabled rows; only update it in the lead thread.
if (bProgress)
@@ -2236,8 +2243,9 @@ public:
void push_back( XclExpRow *pRow ) { maRows.push_back( pRow ); }
virtual void doWork() override
{
+ ScfUInt16Vec aXFIndexes( mrColXFIndexes.size(), EXC_XF_NOTFOUND );
for (XclExpRow* p : maRows)
- p->Finalize( mrColXFIndexes, mnStartColAllDefault, mbProgress );
+ p->Finalize( mrColXFIndexes, aXFIndexes, mnStartColAllDefault, mbProgress );
}
};
@@ -2261,8 +2269,9 @@ void XclExpRowBuffer::Finalize( XclExpDefaultRowData& rDefRowData,
#endif
if (nThreads == 1)
{
+ ScfUInt16Vec aXFIndexes( rColXFIndexes.size(), EXC_XF_NOTFOUND );
for (auto& rEntry : maRowMap)
- rEntry.second->Finalize( rColXFIndexes, nStartColAllDefault, true );
+ rEntry.second->Finalize( rColXFIndexes, aXFIndexes, nStartColAllDefault, true );
}
else
{
diff --git a/sc/source/filter/inc/xetable.hxx b/sc/source/filter/inc/xetable.hxx
index 1e9e7cd45d2c..ed16140f6d68 100644
--- a/sc/source/filter/inc/xetable.hxx
+++ b/sc/source/filter/inc/xetable.hxx
@@ -853,6 +853,7 @@ public:
/** Converts all XF identifiers into the Excel XF indexes. */
void Finalize( const ScfUInt16Vec& rColXFIndexes,
+ ScfUInt16Vec& aXFIndexes,
size_t nStartColAllDefault,
bool bUpdateProgress );