diff options
author | Eike Rathke <erack@redhat.com> | 2016-04-19 11:03:15 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2016-04-19 11:08:01 +0200 |
commit | 35abb3aacb4072171e8c580e1306e3c44e368646 (patch) | |
tree | 9ab5451d329633596b8bf10df4644d74eb2504b0 /sc | |
parent | 97dee1df42dc2933d1350eb1e67361674614417a (diff) |
call StartNeededListeners() only on affected columns, tdf#99322 follow-up
Iterating over the entire document is an unnecessary performancce
penalty if the set of affected columns is already known.
Change-Id: I84598066f878ca4615d6a5e1d6c70ebaa686e446
Diffstat (limited to 'sc')
-rw-r--r-- | sc/inc/columnset.hxx | 2 | ||||
-rw-r--r-- | sc/inc/document.hxx | 2 | ||||
-rw-r--r-- | sc/inc/listenercontext.hxx | 4 | ||||
-rw-r--r-- | sc/source/core/data/columnset.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/document.cxx | 12 | ||||
-rw-r--r-- | sc/source/core/data/document10.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/listenercontext.cxx | 10 | ||||
-rw-r--r-- | sc/source/core/data/table2.cxx | 19 |
8 files changed, 63 insertions, 6 deletions
diff --git a/sc/inc/columnset.hxx b/sc/inc/columnset.hxx index 3ee8fbaed933..ddf08ba8f860 100644 --- a/sc/inc/columnset.hxx +++ b/sc/inc/columnset.hxx @@ -30,6 +30,8 @@ class ColumnSet public: void set(SCTAB nTab, SCCOL nCol); void getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const; + bool hasTab( SCTAB nTab ) const; + bool empty() const; }; } diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx index 9a52748557db..203996fabfd7 100644 --- a/sc/inc/document.hxx +++ b/sc/inc/document.hxx @@ -79,6 +79,7 @@ class RefMovedHint; struct SortUndoParam; struct ReorderParam; class FormulaGroupAreaListener; +class ColumnSet; } @@ -1980,6 +1981,7 @@ public: void SetHardRecalcState( HardRecalcState eVal ) { eHardRecalcState = eVal; } void StartAllListeners(); void StartNeededListeners(); + void StartNeededListeners( std::shared_ptr<const sc::ColumnSet>& rpColSet ); void StartAllListeners( const ScRange& rRange ); void SetForcedFormulas( bool bVal ) { bHasForcedFormulas = bVal; } diff --git a/sc/inc/listenercontext.hxx b/sc/inc/listenercontext.hxx index f9b95884d41d..d1576cb92149 100644 --- a/sc/inc/listenercontext.hxx +++ b/sc/inc/listenercontext.hxx @@ -22,16 +22,20 @@ namespace sc { struct ColumnBlockPosition; class ColumnBlockPositionSet; +class ColumnSet; class StartListeningContext { ScDocument& mrDoc; std::shared_ptr<ColumnBlockPositionSet> mpSet; + std::shared_ptr<const ColumnSet> mpColSet; public: StartListeningContext(const StartListeningContext&) = delete; const StartListeningContext& operator=(const StartListeningContext&) = delete; StartListeningContext(ScDocument& rDoc); StartListeningContext(ScDocument& rDoc, const std::shared_ptr<ColumnBlockPositionSet>& pSet); + void setColumnSet( std::shared_ptr<const ColumnSet>& pColSet ); + std::shared_ptr<const ColumnSet> getColumnSet() const; ScDocument& getDoc() { return mrDoc;} ColumnBlockPosition* getBlockPosition(SCTAB nTab, SCCOL nCol); diff --git a/sc/source/core/data/columnset.cxx b/sc/source/core/data/columnset.cxx index 84935e515e43..1af137117f5d 100644 --- a/sc/source/core/data/columnset.cxx +++ b/sc/source/core/data/columnset.cxx @@ -52,6 +52,16 @@ void ColumnSet::getColumns(SCTAB nTab, std::vector<SCCOL>& rCols) const rCols.swap(aCols); } +bool ColumnSet::hasTab(SCTAB nTab) const +{ + return maTabs.find(nTab) != maTabs.end(); +} + +bool ColumnSet::empty() const +{ + return maTabs.empty(); +} + } /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx index ead717811a9a..faed5470cf2e 100644 --- a/sc/source/core/data/document.cxx +++ b/sc/source/core/data/document.cxx @@ -2596,10 +2596,14 @@ void ScDocument::CopyBlockFromClip( // For URM_MOVE group listeners may have been removed, // re-establish them. - /* TODO: actually only those in - * sc::RefUpdateContext::maRegroupCols are affected, - * come up with a start listeners that takes such. */ - StartNeededListeners(); + if (!aRefCxt.maRegroupCols.empty()) + { + /* TODO: holding the ColumnSet in a shared_ptr at + * RefUpdateContext would eliminate the need of + * copying it here. */ + std::shared_ptr<const sc::ColumnSet> pColSet( new sc::ColumnSet( aRefCxt.maRegroupCols)); + StartNeededListeners( pColSet); + } SetInsertingFromOtherDoc( bOldInserting); } diff --git a/sc/source/core/data/document10.cxx b/sc/source/core/data/document10.cxx index d73eac5f8785..6bd177582790 100644 --- a/sc/source/core/data/document10.cxx +++ b/sc/source/core/data/document10.cxx @@ -396,6 +396,11 @@ class StartNeededListenersHandler : public std::unary_function<ScTable*, void> std::shared_ptr<sc::StartListeningContext> mpCxt; public: explicit StartNeededListenersHandler( ScDocument& rDoc ) : mpCxt(new sc::StartListeningContext(rDoc)) {} + explicit StartNeededListenersHandler( ScDocument& rDoc, std::shared_ptr<const sc::ColumnSet>& rpColSet ) : + mpCxt(new sc::StartListeningContext(rDoc)) + { + mpCxt->setColumnSet( rpColSet); + } void operator() (ScTable* p) { @@ -411,6 +416,11 @@ void ScDocument::StartNeededListeners() std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this)); } +void ScDocument::StartNeededListeners( std::shared_ptr<const sc::ColumnSet>& rpColSet ) +{ + std::for_each(maTabs.begin(), maTabs.end(), StartNeededListenersHandler(*this, rpColSet)); +} + void ScDocument::StartAllListeners( const ScRange& rRange ) { std::shared_ptr<sc::ColumnBlockPositionSet> pPosSet(new sc::ColumnBlockPositionSet(*this)); diff --git a/sc/source/core/data/listenercontext.cxx b/sc/source/core/data/listenercontext.cxx index 75010007d506..44d9df23f3a9 100644 --- a/sc/source/core/data/listenercontext.cxx +++ b/sc/source/core/data/listenercontext.cxx @@ -20,6 +20,16 @@ StartListeningContext::StartListeningContext( ScDocument& rDoc, const std::shared_ptr<ColumnBlockPositionSet>& pSet) : mrDoc(rDoc), mpSet(pSet) {} +void StartListeningContext::setColumnSet( std::shared_ptr<const ColumnSet>& rpColSet ) +{ + mpColSet = rpColSet; +} + +std::shared_ptr<const ColumnSet> StartListeningContext::getColumnSet() const +{ + return mpColSet; +} + ColumnBlockPosition* StartListeningContext::getBlockPosition(SCTAB nTab, SCCOL nCol) { return mpSet->getBlockPosition(nTab, nCol); diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index f11c6f090912..e76aaa39456a 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -53,6 +53,7 @@ #include "columnspanset.hxx" #include <rowheightcontext.hxx> #include <refhint.hxx> +#include "listenercontext.hxx" #include "scitems.hxx" #include <editeng/boxitem.hxx> @@ -1033,8 +1034,22 @@ const ScColumn* ScTable::FetchColumn( SCCOL nCol ) const void ScTable::StartListeners( sc::StartListeningContext& rCxt, bool bAll ) { - for (SCCOL i=0; i<=MAXCOL; i++) - aCol[i].StartListeners(rCxt, bAll); + std::shared_ptr<const sc::ColumnSet> pColSet = rCxt.getColumnSet(); + if (!pColSet) + { + for (SCCOL i=0; i<=MAXCOL; i++) + aCol[i].StartListeners(rCxt, bAll); + } + else if (pColSet->hasTab( nTab)) + { + std::vector<SCCOL> aColumns; + pColSet->getColumns( nTab, aColumns); + for (auto i : aColumns) + { + if (0 <= i && i <= MAXCOL) + aCol[i].StartListeners(rCxt, bAll); + } + } } void ScTable::AttachFormulaCells( |