summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKohei Yoshida <kyoshida@novell.com>2011-07-25 10:21:01 -0400
committerPetr Mladek <pmladek@suse.cz>2011-07-25 17:24:53 +0200
commita51e448168c89e2e485231749f8ac9014ea8f7b6 (patch)
tree55df5825eee34f61f535163b275df1ceafb53c39
parente64d3793a10cf6d253384308db3de671a8b4a922 (diff)
fdo#39236: Better way to remove DP objects without reversing order.
The old fix reversed the order of the elements even when no elements were deleted. This is better & cleaner. Thanks to David Tardon for suggesting me this. Signed-off-by: Michael Meeks <michael.meeks@novell.com> Signed-off-by: Petr Mladek <pmladek@suse.cz> Signed-off-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
-rw-r--r--sc/source/core/data/dpobject.cxx30
1 files changed, 21 insertions, 9 deletions
diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 9d7eae9608cd..4490d999c665 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -83,6 +83,7 @@
using namespace com::sun::star;
using ::std::vector;
+using ::std::unary_function;
using ::boost::shared_ptr;
using ::com::sun::star::uno::Sequence;
using ::com::sun::star::uno::Reference;
@@ -2554,6 +2555,25 @@ ScDPCollection::~ScDPCollection()
maTables.clear();
}
+namespace {
+
+/**
+ * Unary predicate to match DP objects by the table ID.
+ */
+class MatchByTable : public unary_function<ScDPObject, bool>
+{
+ SCTAB mnTab;
+public:
+ MatchByTable(SCTAB nTab) : mnTab(nTab) {}
+
+ bool operator() (const ScDPObject& rObj) const
+ {
+ return rObj.GetOutRange().aStart.Tab() == mnTab;
+ }
+};
+
+}
+
bool ScDPCollection::ClearCache(ScDPObject* pDPObj)
{
if (pDPObj->IsSheetData())
@@ -2591,15 +2611,7 @@ bool ScDPCollection::ClearCache(ScDPObject* pDPObj)
void ScDPCollection::DeleteOnTab( SCTAB nTab )
{
- TablesType aNewTables;
- while (!maTables.empty())
- {
- TablesType::auto_type xDP = maTables.pop_back();
- if (xDP->GetOutRange().aStart.Tab() != nTab)
- // Not on this sheet. Keep it.
- aNewTables.push_back(xDP.release());
- }
- maTables.swap(aNewTables);
+ maTables.erase_if(MatchByTable(nTab));
}
void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode,