sc/inc/attarray.hxx | 4 +-- sc/inc/column.hxx | 6 ++-- sc/inc/document.hxx | 6 ++-- sc/inc/table.hxx | 6 ++-- sc/source/core/data/attarray.cxx | 6 ++-- sc/source/core/data/column2.cxx | 12 ++++----- sc/source/core/data/documen3.cxx | 10 ++++---- sc/source/core/data/document.cxx | 48 ++++++++++++++++++++++----------------- sc/source/core/data/table4.cxx | 12 ++++----- 9 files changed, 59 insertions(+), 51 deletions(-)
New commits: commit 8fd7a53d3cf1ed788c705cafb443801203787c9d Author: Eike Rathke <[email protected]> Date: Wed Jan 22 00:07:14 2014 +0100 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 diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index bee7eed..ec2512f 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 972cc44..4d45f56 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; commit 57b8e7c96bafb97f881b7db73624693392e13540 Author: Eike Rathke <[email protected]> Date: Tue Jan 21 17:46:32 2014 +0100 some clean-up of 6b8704d974abd4ab7fb58036a961fa0b7136aaa7 const methods, removed this->..., naming Change-Id: I0db1cf445936bab04003062bc59ce0a0c2fc8b71 diff --git a/sc/inc/attarray.hxx b/sc/inc/attarray.hxx index c2789b3..2d52279 100644 --- a/sc/inc/attarray.hxx +++ b/sc/inc/attarray.hxx @@ -189,9 +189,9 @@ public: void DeleteHardAttr( SCROW nStartRow, SCROW nEndRow ); /* i123909: Pre-calculate needed memory, and pre-reserve enough memory */ - bool Reserve( SCSIZE nCount ); + bool Reserve( SCSIZE nReserve ); SCSIZE Count() const { return nCount; } - SCSIZE Count( SCROW nRw1, SCROW nRw2 ); + SCSIZE Count( SCROW nRow1, SCROW nRow2 ) const; }; // Iterator for attributes diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx index 8b09db3..afe9f6a 100644 --- a/sc/inc/column.hxx +++ b/sc/inc/column.hxx @@ -536,9 +536,9 @@ public: void DumpFormulaGroups() const; #endif - SCSIZE GetPatternCount( ); - SCSIZE GetPatternCount( SCROW nRw1, SCROW nRw2 ); - bool ReservedPatternCount( SCSIZE nReserved ); + SCSIZE GetPatternCount() const; + SCSIZE GetPatternCount( SCROW nRow1, SCROW nRow2 ) const; + bool ReservePatternCount( SCSIZE nReserve ); private: sc::CellStoreType::iterator GetPositionToInsert( SCROW nRow ); diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 3fe416c..2f1ecdc 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -2089,9 +2089,9 @@ private: // CLOOK-Impl-methods std::map< SCTAB, ScSortParam > mSheetSortParams; - SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol ); - SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRw1, SCROW nRw2 ); - bool ReservedPatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserved ); + SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol ) const; + SCSIZE GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const; + bool ReservePatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserve ); }; inline void ScDocument::GetSortParam( ScSortParam& rParam, SCTAB nTab ) { diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx index 68a1791..19dbb00 100644 --- a/sc/inc/table.hxx +++ b/sc/inc/table.hxx @@ -346,9 +346,9 @@ public: void SetValue( SCCOL nCol, SCROW nRow, const double& rVal ); void SetError( SCCOL nCol, SCROW nRow, sal_uInt16 nError); - SCSIZE GetPatternCount( SCCOL nCol ); - SCSIZE GetPatternCount( SCCOL nCol, SCROW nRw1, SCROW nRw2 ); - bool ReservedPatternCount( SCCOL nCol, SCSIZE nReserved ); + SCSIZE GetPatternCount( SCCOL nCol ) const; + SCSIZE GetPatternCount( SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const; + bool ReservePatternCount( SCCOL nCol, SCSIZE nReserve ); void SetRawString( SCCOL nCol, SCROW nRow, const OUString& rStr ); void SetRawString( SCCOL nCol, SCROW nRow, const svl::SharedString& rStr ); diff --git a/sc/source/core/data/attarray.cxx b/sc/source/core/data/attarray.cxx index 2bfccee..bee7eed 100644 --- a/sc/source/core/data/attarray.cxx +++ b/sc/source/core/data/attarray.cxx @@ -2458,7 +2458,7 @@ bool ScAttrArray::SearchStyleRange( return false; } -SCSIZE ScAttrArray::Count( SCROW nStartRow, SCROW nEndRow ) +SCSIZE ScAttrArray::Count( SCROW nStartRow, SCROW nEndRow ) const { SCSIZE nIndex1, nIndex2; @@ -2466,7 +2466,7 @@ SCSIZE ScAttrArray::Count( SCROW nStartRow, SCROW nEndRow ) return 0; if( !Search( nEndRow, nIndex2 ) ) - nIndex2 = this->nCount - 1; + nIndex2 = nCount - 1; return nIndex2 - nIndex1 + 1; } diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index bea9179..b891276 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -3489,19 +3489,19 @@ sal_uInt32 ScColumn::GetCodeCount() const return aFunc.getCount(); } -SCSIZE ScColumn::GetPatternCount() +SCSIZE ScColumn::GetPatternCount() const { - return this->pAttrArray ? this->pAttrArray->Count() : 0; + return pAttrArray ? pAttrArray->Count() : 0; } -SCSIZE ScColumn::GetPatternCount( SCROW nRw1, SCROW nRw2 ) +SCSIZE ScColumn::GetPatternCount( SCROW nRow1, SCROW nRow2 ) const { - return this->pAttrArray ? this->pAttrArray->Count( nRw1, nRw2 ) : 0; + return pAttrArray ? pAttrArray->Count( nRow1, nRow2 ) : 0; } -bool ScColumn::ReservedPatternCount( SCSIZE nReserved ) +bool ScColumn::ReservePatternCount( SCSIZE nReserve ) { - return this->pAttrArray ? this->pAttrArray->Reserve( nReserved ) : false; + return pAttrArray ? pAttrArray->Reserve( nReserve ) : false; } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/documen3.cxx b/sc/source/core/data/documen3.cxx index 2fda595..dd25b7b 100644 --- a/sc/source/core/data/documen3.cxx +++ b/sc/source/core/data/documen3.cxx @@ -2016,7 +2016,7 @@ void ScDocument::ExtendPrintArea( OutputDevice* pDev, SCTAB nTab, maTabs[nTab]->ExtendPrintArea( pDev, nStartCol, nStartRow, rEndCol, nEndRow ); } -SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol ) +SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol ) const { if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) return maTabs[nTab]->GetPatternCount( nCol ); @@ -2024,18 +2024,18 @@ SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol ) return 0; } -SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRw1, SCROW nRw2 ) +SCSIZE ScDocument::GetPatternCount( SCTAB nTab, SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const { if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) - return maTabs[nTab]->GetPatternCount( nCol, nRw1, nRw2 ); + return maTabs[nTab]->GetPatternCount( nCol, nRow1, nRow2 ); else return 0; } -bool ScDocument::ReservedPatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserved ) +bool ScDocument::ReservePatternCount( SCTAB nTab, SCCOL nCol, SCSIZE nReserve ) { if( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] ) - return maTabs[nTab]->ReservedPatternCount( nCol, nReserved ); + return maTabs[nTab]->ReservePatternCount( nCol, nReserve ); else return false; } diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index 3ed9907..972cc44 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2714,7 +2714,7 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar vvPatternCount[i].resize( vTables.size() ); for (std::vector< SCTAB >::size_type j = 0; j < vTables.size(); ++j) - vvPatternCount[i][j] = this->GetPatternCount( vTables[j], nCol1+i ); + vvPatternCount[i][j] = GetPatternCount( vTables[j], nCol1+i ); } } @@ -2759,7 +2759,7 @@ void ScDocument::CopyFromClip( const ScRange& rDestRange, const ScMarkData& rMar vvPatternCount[i].resize( vTables.size() ); for (std::vector< SCTAB >::size_type j = 0; j<vTables.size(); ++j) - this->ReservedPatternCount( vTables[j], nCol1+i, vvPatternCount[i][j] + ( this->GetPatternCount( vTables[j], nCol1+i, nR1, nR2 ) ) * ( ( nRow2 - nRow1 + 1 ) / ( nYw + 1 ) ) ); + ReservePatternCount( vTables[j], nCol1+i, vvPatternCount[i][j] + ( GetPatternCount( vTables[j], nCol1+i, nR1, nR2 ) ) * ( ( nRow2 - nRow1 + 1 ) / ( nYw + 1 ) ) ); } bNeedPerformanceOptimization4Pattern = false; diff --git a/sc/source/core/data/table4.cxx b/sc/source/core/data/table4.cxx index 3afef71..0755cd6 100644 --- a/sc/source/core/data/table4.cxx +++ b/sc/source/core/data/table4.cxx @@ -2076,7 +2076,7 @@ void ScTable::CompileColRowNameFormula() for (SCCOL i=0; i<=MAXCOL; i++) aCol[i].CompileColRowNameFormula(); } -SCSIZE ScTable::GetPatternCount( SCCOL nCol ) +SCSIZE ScTable::GetPatternCount( SCCOL nCol ) const { if( ValidCol( nCol ) ) return aCol[nCol].GetPatternCount(); @@ -2084,18 +2084,18 @@ SCSIZE ScTable::GetPatternCount( SCCOL nCol ) return 0; } -SCSIZE ScTable::GetPatternCount( SCCOL nCol, SCROW nRw1, SCROW nRw2 ) +SCSIZE ScTable::GetPatternCount( SCCOL nCol, SCROW nRow1, SCROW nRow2 ) const { - if( ValidCol( nCol ) && ValidRow( nRw1 ) && ValidRow( nRw2 ) ) - return aCol[nCol].GetPatternCount( nRw1, nRw2 ); + if( ValidCol( nCol ) && ValidRow( nRow1 ) && ValidRow( nRow2 ) ) + return aCol[nCol].GetPatternCount( nRow1, nRow2 ); else return 0; } -bool ScTable::ReservedPatternCount( SCCOL nCol, SCSIZE nReserved ) +bool ScTable::ReservePatternCount( SCCOL nCol, SCSIZE nReserve ) { if( ValidCol( nCol ) ) - return aCol[nCol].ReservedPatternCount( nReserved ); + return aCol[nCol].ReservePatternCount( nReserve ); else return false; } _______________________________________________ Libreoffice-commits mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits
