sc/Library_sc.mk                     |    1 
 sc/inc/colcontainer.hxx              |   44 +++++++++++++++++++++++------------
 sc/inc/column.hxx                    |    1 
 sc/inc/table.hxx                     |    6 ++--
 sc/source/core/data/colcontainer.cxx |   35 ---------------------------
 sc/source/core/data/document.cxx     |    2 -
 sc/source/core/data/table1.cxx       |    8 +++---
 sc/source/core/data/table2.cxx       |    4 +--
 8 files changed, 41 insertions(+), 60 deletions(-)

New commits:
commit a6b8618c95717c6e4ea5a42edcd9997c5e9f3b9b
Author:     Ashod Nakashian <ashod.nakash...@collabora.co.uk>
AuthorDate: Wed Nov 22 22:17:37 2017 -0500
Commit:     Jan Holesovsky <ke...@collabora.com>
CommitDate: Mon Nov 5 12:12:44 2018 +0100

    sc: simplify ScColContainer
    
    Less clutter, no indirection and smaller memory footprint.
    
    Reviewed-on: https://gerrit.libreoffice.org/45379
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>
    (cherry picked from commit 7c8c2b5e3a569d60375975d6fbad32e3c3c48c9d)
    (cherry picked from commit f64ff421a338ac22981f7fa93166f179c158a4d0)
    
    Change-Id: Ic24272e9853a7af28df62298fd26e7edce554986
    Reviewed-on: https://gerrit.libreoffice.org/58155
    Reviewed-by: Jan Holesovsky <ke...@collabora.com>
    Tested-by: Jan Holesovsky <ke...@collabora.com>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index 65c895501cd8..d7851c4a83f9 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -102,7 +102,6 @@ $(eval $(call gb_Library_add_exception_objects,sc,\
     sc/source/core/data/cellvalues \
     sc/source/core/data/clipcontext \
     sc/source/core/data/clipparam \
-    sc/source/core/data/colcontainer \
     sc/source/core/data/column \
     sc/source/core/data/column2 \
     sc/source/core/data/column3 \
diff --git a/sc/inc/colcontainer.hxx b/sc/inc/colcontainer.hxx
index bf2bd206850f..f134b64aa27a 100644
--- a/sc/inc/colcontainer.hxx
+++ b/sc/inc/colcontainer.hxx
@@ -22,29 +22,35 @@
 
 #include "types.hxx"
 #include "address.hxx"
+#include "column.hxx"
 
 #include <vector>
 
-class ScColumn;
-class ScDocument;
-
-class ScColContainer
+class ScColContainer final
 {
-    typedef std::vector<ScColumn*> ScColumnVector;
+    typedef std::vector<ScColumn> ScColumnVector;
     ScColumnVector    aCols;
 
 public:
-    ScColContainer( const size_t nSize );
-    ~ScColContainer() COVERITY_NOEXCEPT_FALSE;
+
+    ScColContainer(const size_t nSize)
+      : aCols(nSize)
+    {
+    }
+
+    ~ScColContainer() COVERITY_NOEXCEPT_FALSE
+    {
+        Clear();
+    }
 
     const ScColumn& operator[] ( const size_t nIndex ) const
     {
-        return *aCols[nIndex];
+        return aCols[nIndex];
     }
 
     ScColumn& operator[] ( const size_t nIndex )
     {
-        return *aCols[nIndex];
+        return aCols[nIndex];
     }
 
     SCCOL size() const
@@ -57,27 +63,37 @@ public:
         return aCols.empty();
     }
 
-    void resize( const size_t aNewSize );
+    void resize(const size_t aNewSize)
+    {
+        aCols.resize(aNewSize);
+    }
+
+    void Clear()
+    {
+        for (ScColumn& rCol: aCols)
+            rCol.PrepareBroadcastersForDestruction();
 
-    void Clear();
+        aCols.clear();
+    }
 
     const ScColumn& back() const
     {
         assert(aCols.size() > 0);
-        return *aCols.back();
+        return aCols.back();
     }
 
     ScColumn& back()
     {
         assert(aCols.size() > 0);
-        return *aCols.back();
+        return aCols.back();
     }
 
+    ScColumnVector::iterator begin() { return aCols.begin(); }
+    ScColumnVector::iterator end() { return aCols.end(); }
     ScColumnVector::const_iterator begin() const { return aCols.begin(); }
     ScColumnVector::const_iterator end() const { return aCols.end(); }
 };
 
-
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 7eeefd6e96b7..094e8d956e70 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -186,6 +186,7 @@ public:
     };
 
     ScColumn();
+    ScColumn(ScColumn&&) = default; // Required by ScColContainer::resize
     ~ScColumn() COVERITY_NOEXCEPT_FALSE;
 
     void        Init(SCCOL nNewCol, SCTAB nNewTab, ScDocument* pDoc, bool 
bEmptyAttrArray = false);
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index d6af98d394f0..f54f42c4c3eb 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -128,16 +128,16 @@ class ScColumnsRange final
                             const SCCOL*,             // pointer
                             SCCOL>                    // reference
     {
-        std::vector<ScColumn*>::const_iterator maColIter;
+        std::vector<ScColumn>::const_iterator maColIter;
     public:
-        explicit Iterator(const std::vector<ScColumn*>::const_iterator& 
colIter) : maColIter(colIter) {}
+        explicit Iterator(const std::vector<ScColumn>::const_iterator& 
colIter) : maColIter(colIter) {}
 
         Iterator& operator++() { ++maColIter; return *this;}
         Iterator& operator--() { --maColIter; return *this;}
 
         bool operator==(const Iterator & rOther) const {return maColIter == 
rOther.maColIter;}
         bool operator!=(const Iterator & rOther) const {return !(*this == 
rOther);}
-        reference operator*() const {return (*maColIter)->GetCol();}
+        reference operator*() const {return (*maColIter).GetCol();}
     };
 
     ScColumnsRange(const Iterator & rBegin, const Iterator & rEnd) : 
maBegin(rBegin), maEnd(rEnd) {}
diff --git a/sc/source/core/data/colcontainer.cxx 
b/sc/source/core/data/colcontainer.cxx
index 44dcf5ff7782..b2f93e975edd 100644
--- a/sc/source/core/data/colcontainer.cxx
+++ b/sc/source/core/data/colcontainer.cxx
@@ -18,39 +18,4 @@
  */
 
 
-#include <colcontainer.hxx>
-#include <column.hxx>
-#include <document.hxx>
-
-ScColContainer::ScColContainer( const size_t nSize )
-{
-    aCols.resize( nSize );
-    for ( size_t nCol = 0; nCol < nSize; ++nCol )
-        aCols[nCol] = new ScColumn;
-}
-
-ScColContainer::~ScColContainer() COVERITY_NOEXCEPT_FALSE
-{
-    Clear();
-}
-
-void ScColContainer::Clear()
-{
-    SCCOL nSize = size();
-    for ( SCCOL nIdx = 0; nIdx < nSize; ++nIdx )
-    {
-        aCols[nIdx]->PrepareBroadcastersForDestruction();
-        delete aCols[nIdx];
-    }
-    aCols.clear();
-}
-
-void ScColContainer::resize( const size_t aNewColSize )
-{
-    size_t aOldColSize = aCols.size();
-    aCols.resize( aNewColSize );
-    for ( size_t nCol = aOldColSize; nCol < aNewColSize; ++nCol )
-        aCols[nCol] = new ScColumn;
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index f5a3218301f5..7d6d0c24f3a3 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -2547,7 +2547,7 @@ ScColumnsRange ScDocument::GetColumnsRange( SCTAB nTab, 
SCCOL nColBegin, SCCOL n
 {
     if (!TableExists(nTab))
     {
-        std::vector<ScColumn*> aEmptyVector;
+        std::vector<ScColumn> aEmptyVector;
         return ScColumnsRange(ScColumnsRange::Iterator(aEmptyVector.begin()),
                               ScColumnsRange::Iterator(aEmptyVector.end()));
     }
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 4ce1306258f1..062184f9dbdb 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -1673,14 +1673,14 @@ void ScTable::UpdateReference(
 void ScTable::UpdateTranspose( const ScRange& rSource, const ScAddress& rDest,
                                     ScDocument* pUndoDoc )
 {
-    for (auto const & rpCol : aCol)
-        rpCol->UpdateTranspose( rSource, rDest, pUndoDoc );
+    for (auto& rpCol : aCol)
+        rpCol.UpdateTranspose( rSource, rDest, pUndoDoc );
 }
 
 void ScTable::UpdateGrow( const ScRange& rArea, SCCOL nGrowX, SCROW nGrowY )
 {
-    for (auto const & rpCol : aCol)
-        rpCol->UpdateGrow( rArea, nGrowX, nGrowY );
+    for (auto& rpCol : aCol)
+        rpCol.UpdateGrow( rArea, nGrowX, nGrowY );
 }
 
 void ScTable::UpdateInsertTab( sc::RefUpdateInsertTabContext& rCxt )
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index f18bb9ed8ce5..ed6046dea2a0 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1670,8 +1670,8 @@ CommentCaptionState 
ScTable::GetAllNoteCaptionsState(const ScRange& rRange, std:
 
 void ScTable::GetUnprotectedCells( ScRangeList& rRangeList ) const
 {
-    for (auto pCol : aCol)
-        pCol->GetUnprotectedCells(0, MAXROW, rRangeList);
+    for (auto& pCol : aCol)
+        pCol.GetUnprotectedCells(0, MAXROW, rRangeList);
 }
 
 bool ScTable::ContainsNotesInRange( const ScRange& rRange ) const
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to