[Libreoffice-commits] .: 3 commits - sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Wed Jan 19 21:42:20 PST 2011


 sc/source/core/data/dpobject.cxx |   51 ++++++++++++++++-----------------------
 sc/source/core/data/makefile.mk  |    4 ---
 2 files changed, 22 insertions(+), 33 deletions(-)

New commits:
commit 4707861e839679dca8b119246a51c10b422e5acd
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Thu Jan 20 00:32:38 2011 -0500

    Let's hide this ugliness inside the remove-erase idiom.
    
    So, since I can't rely on the iterator returned from vector::erase(),
    and I can't keep the iterator of the erased element (which is probably
    invalidated after the erase call), I have to erase elements by
    other means.  Luckily this remove-erase idiom doesn't cause a segfault,
    and appears to do the right thing.

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 3b754bd..5e1a43f 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -80,6 +80,8 @@
 
 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;
@@ -2416,15 +2418,30 @@ ScDPCollection::~ScDPCollection()
     maTables.clear();
 }
 
-void ScDPCollection::DeleteOnTab( SCTAB nTab )
+namespace {
+
+/**
+ * Unary predicate to match DP objects by the table ID.
+ */
+class MatchByTable : public unary_function<bool, ScDPObject>
 {
-    TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end();
-    for (; itr != itrEnd; ++itr)
+    SCTAB mnTab;
+public:
+    MatchByTable(SCTAB nTab) : mnTab(nTab) {}
+
+    bool operator() (const ScDPObject& rObj) const
     {
-        const ScDPObject& rObj = *itr;
-        if (rObj.GetOutRange().aStart.Tab() == nTab)
-            maTables.erase(itr);
+        return rObj.GetOutRange().aStart.Tab() == mnTab;
     }
+};
+
+}
+
+void ScDPCollection::DeleteOnTab( SCTAB nTab )
+{
+    maTables.erase(
+        remove_if(maTables.begin(), maTables.end(), MatchByTable(nTab)),
+        maTables.end());
 }
 
 void ScDPCollection::UpdateReference( UpdateRefMode eUpdateRefMode,
commit 9bcecbb876aa8a4a9e3aa6371dbddb3f29345518
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Jan 19 23:24:53 2011 -0500

    Don't rely on the returned iterator from vector::erase(itr).
    
    The standard specifies that when you erase an element in vector via
    
    vector::erase(iterator)
    
    it returns the new position of the element after the erased element,
    or the end position in case the call deletes the last element.
    *But*, the stlport version of vector returns the iterator that points
    to the position where the deleted element was, which may be correct
    if the vector is not empty after the delete, but if it's empty it
    points to an invalid location.  So, if you have a loop like this
    
    vector<myclass> vcon;
    ...
    while (itr != itrEnd)
    {
        if (some condition to trigger removal)
            itr = vcon.erase(itr);
        else
            ++itr;
    }
    
    the standard says it should work, but with stlport it leads to a
    surprise ending when size() == 1.

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 21c6943..3b754bd 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2419,14 +2419,11 @@ ScDPCollection::~ScDPCollection()
 void ScDPCollection::DeleteOnTab( SCTAB nTab )
 {
     TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end();
-    while (itr != itrEnd)
+    for (; itr != itrEnd; ++itr)
     {
         const ScDPObject& rObj = *itr;
         if (rObj.GetOutRange().aStart.Tab() == nTab)
-            // returns the next position after the erased element.
-            itr = maTables.erase(itr);
-        else
-            ++itr;
+            maTables.erase(itr);
     }
 }
 
commit b70937f47e062ac87bf15bb2f69498e8c140bd5c
Author: Kohei Yoshida <kyoshida at novell.com>
Date:   Wed Jan 19 23:21:51 2011 -0500

    Removed the ugly stlport workaround code.
    
    It's too ugly for me to live with.  I'll find a better, and hopefully
    cleaner workaround.

diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx
index 782340b..21c6943 100644
--- a/sc/source/core/data/dpobject.cxx
+++ b/sc/source/core/data/dpobject.cxx
@@ -2418,17 +2418,6 @@ ScDPCollection::~ScDPCollection()
 
 void ScDPCollection::DeleteOnTab( SCTAB nTab )
 {
-#ifdef STLPORT_WORKAROUND
-    // We do this only because STLPort crashes when erasing an element when
-    // the container only contains one element.
-    if (maTables.size() == 1)
-    {
-        if (maTables.back().GetOutRange().aStart.Tab() == nTab)
-            maTables.clear();
-        return;
-    }
-#endif
-
     TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end();
     while (itr != itrEnd)
     {
@@ -2635,16 +2624,6 @@ void ScDPCollection::FreeTable(ScDPObject* pDPObj)
     const ScAddress& s = rOutRange.aStart;
     const ScAddress& e = rOutRange.aEnd;
     pDoc->RemoveFlagsTab(s.Col(), s.Row(), e.Col(), e.Row(), s.Tab(), SC_MF_DP_TABLE);
-#ifdef STLPORT_WORKAROUND
-    // We do this only because STLPort crashes when erasing an element when
-    // the container only contains one element.
-    if (maTables.size() == 1)
-    {
-        if (&maTables.back() == pDPObj)
-            maTables.clear();
-        return;
-    }
-#endif
     TablesType::iterator itr = maTables.begin(), itrEnd = maTables.end();
     for (; itr != itrEnd; ++itr)
     {
diff --git a/sc/source/core/data/makefile.mk b/sc/source/core/data/makefile.mk
index 1fbcd3c..efb3fca 100644
--- a/sc/source/core/data/makefile.mk
+++ b/sc/source/core/data/makefile.mk
@@ -43,10 +43,6 @@ AUTOSEG=true
 
 # --- Files --------------------------------------------------------
 
-.IF "$(USE_SYSTEM_STL)"!="YES"
-CFLAGSCXX+=-DSTLPORT_WORKAROUND
-.ENDIF
-
 SLOFILES =  \
     $(EXCEPTIONSFILES) \
     $(EXCEPTIONSNOOPTFILES) \


More information about the Libreoffice-commits mailing list