[Libreoffice-commits] .: Branch 'libreoffice-3-4-2' - 2 commits - sc/source

Petr Mladek pmladek at kemper.freedesktop.org
Mon Jul 25 08:25:23 PDT 2011


 sc/source/core/data/dpobject.cxx |    7 ++-----
 1 file changed, 2 insertions(+), 5 deletions(-)

New commits:
commit 31b9a3667b8e5a989bc17b8b50473e1dd5880b61
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Mon Jul 25 10:21:01 2011 -0400

    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 at novell.com>
    Signed-off-by: Petr Mladek <pmladek at suse.cz>
    Signed-off-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 3aa7477..d87629a 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,
commit b061f53aafad796b68278194c3eab08613f34142
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Tue Jul 19 14:46:50 2011 -0400

    fdo#39236: Prevent double-deletes during removal of pivot tables.
    
    In short, don't use erase remove(_if) idiom to remove objects from
    boost ptr containers which would cause double deletes because of
    the way remove-like algorithms work.  STL's remove-like algorithms
    create duplicates of the elements instead of re-ordering them by
    design, and this obviously doesn't work well with containers
    containing pointers.
    
    IMPORTANT: this will get a better incremental fix
    
    Signed-off-by: David Tardon <dtardon at redhat.com>
    Signed-off-by: Petr Mladek <pmladek at suse.cz>
    Signed-off-by: Michael Meeks <michael.meeks at novell.com>
    Signed-off-by: Markus Mohrhard <markus.mohrhard at googlemail.com>

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 4426763..3aa7477 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -83,8 +83,6 @@
 
 using namespace com::sun::star;
 using ::std::vector;
-using ::std::unary_function;
-using ::std::remove_if;
 using ::boost::shared_ptr;
 using ::com::sun::star::uno::Sequence;
 using ::com::sun::star::uno::Reference;
@@ -2556,25 +2554,6 @@ ScDPCollection::~ScDPCollection()
     maTables.clear();
 }
 
-namespace {
-
-/**
- * Unary predicate to match DP objects by the table ID.
- */
-class MatchByTable : public unary_function<bool, ScDPObject>
-{
-    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())
@@ -2612,9 +2591,15 @@ bool ScDPCollection::ClearCache(ScDPObject* pDPObj)
 
 void ScDPCollection::DeleteOnTab( SCTAB nTab )
 {
-    maTables.erase(
-        remove_if(maTables.begin(), maTables.end(), MatchByTable(nTab)),
-        maTables.end());
+    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);
 }
 
 void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode,


More information about the Libreoffice-commits mailing list