diff options
author | Eike Rathke <erack@redhat.com> | 2014-01-22 00:07:14 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2014-01-22 01:09:12 +0100 |
commit | 8fd7a53d3cf1ed788c705cafb443801203787c9d (patch) | |
tree | db18fba53ebdf62dd8c16dbf66e94152bbcb0abd | |
parent | 57b8e7c96bafb97f881b7db73624693392e13540 (diff) |
fix-up of 6b8704d974abd4ab7fb58036a961fa0b7136aaa7
Allocation happened also if no attributes were to be pasted and more
memory could had been allocated than actually used. Also that array of
arrays is entirely not needed.
Change-Id: I37a58eea9c42cdc96824ce3e8fba5109921fb35a
-rw-r--r-- | sc/source/core/data/attarray.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 48 |
2 files changed, 29 insertions, 21 deletions
diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index bee7eedf6a70..ec2512f96ba1 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -378,7 +378,7 @@ void ScAttrArray::RemoveCellCharAttribs( SCROW nStartRow, SCROW nEndRow, bool ScAttrArray::Reserve( SCSIZE nReserve ) { - if ( nCount <= nReserve ) + if ( nLimit < nReserve ) { if( ScAttrEntry* pNewData = new (std::nothrow) ScAttrEntry[nReserve] ) { diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 972cc44d48ac..4d45f565ffaf 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2699,23 +2699,14 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar nR2 = nRow2; const SCCOLROW PERFORMANCEOPTIMIZATION4PATTERNTHRESHOLD = 8192; - bool bNeedPerformanceOptimization4Pattern = nRow2 - nRow1 > PERFORMANCEOPTIMIZATION4PATTERNTHRESHOLD; - std::vector< std::vector< SCSIZE > > vvPatternCount( bNeedPerformanceOptimization4Pattern ? nCol2 - nCol1 + 1 : 0 ); + bool bPreallocatePattern = ((nInsFlag & IDF_ATTRIB) && (nRow2 - nRow1 > PERFORMANCEOPTIMIZATION4PATTERNTHRESHOLD)); std::vector< SCTAB > vTables; - if (bNeedPerformanceOptimization4Pattern) + if (bPreallocatePattern) { for (SCTAB i = aCxt.getTabStart(); i <= aCxt.getTabEnd(); ++i) if (maTabs[i] && rMark.GetTableSelect( i ) ) vTables.push_back( i ); - - for (SCSIZE i = 0; i < vvPatternCount.size(); ++i) - { - vvPatternCount[i].resize( vTables.size() ); - - for (std::vector< SCTAB >::size_type j = 0; j < vTables.size(); ++j) - vvPatternCount[i][j] = GetPatternCount( vTables[j], nCol1+i ); - } } do @@ -2752,18 +2743,35 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar if (nC2 > nCol2) nC2 = nCol2; - if (bNeedPerformanceOptimization4Pattern && !vvPatternCount.empty()) + // Preallocate pattern memory once if further chunks are to be pasted. + if (bPreallocatePattern && (nR2+1) <= nRow2) { - for (SCSIZE i = 0; i < vvPatternCount.size(); ++i) + SCROW nR3 = nR2 + 1; + for (size_t j = 0; j < vTables.size(); ++j) { - vvPatternCount[i].resize( vTables.size() ); - - for (std::vector< SCTAB >::size_type j = 0; j<vTables.size(); ++j) - ReservePatternCount( vTables[j], nCol1+i, vvPatternCount[i][j] + ( GetPatternCount( vTables[j], nCol1+i, nR1, nR2 ) ) * ( ( nRow2 - nRow1 + 1 ) / ( nYw + 1 ) ) ); + SCTAB nTab = vTables[j]; + for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol) + { + // Pattern count of the first chunk pasted. + SCSIZE nChunk = GetPatternCount( nTab, nCol, nR1, nR2); + // If it is only one pattern per chunk and chunks are + // pasted consecutively then it will get its range + // enlarged for each chunk and no further allocation + // happens. For non-consecutive chunks we're out of + // luck in this case. + if (nChunk > 1) + { + SCSIZE nNeeded = nChunk * (nRow2 - nR3 + 1) / (nYw + 1); + SCSIZE nRemain = GetPatternCount( nTab, nCol, nR3, nRow2); + if (nNeeded > nRemain) + { + SCSIZE nCurr = GetPatternCount( nTab, nCol); + ReservePatternCount( nTab, nCol, nCurr + nNeeded); + } + } + } } - - bNeedPerformanceOptimization4Pattern = false; - vvPatternCount.clear(); + bPreallocatePattern = false; } nR1 = nR2 + 1; |