[Libreoffice-commits] core.git: sc/inc sc/Library_sc.mk sc/source

Dennis Francis dennisfrancis.in at gmail.com
Thu Feb 4 19:39:17 UTC 2016


 sc/Library_sc.mk                         |    1 
 sc/inc/colcontainer.hxx                  |   88 ++++++++++++++++++++++++++++
 sc/inc/edittextiterator.hxx              |    8 +-
 sc/inc/table.hxx                         |    3 
 sc/source/core/data/colcontainer.cxx     |   95 +++++++++++++++++++++++++++++++
 sc/source/core/data/documentimport.cxx   |    7 --
 sc/source/core/data/edittextiterator.cxx |   41 +++++++++----
 sc/source/core/data/table1.cxx           |   12 +--
 sc/source/core/data/table2.cxx           |    8 +-
 sc/source/core/data/table3.cxx           |    4 -
 10 files changed, 233 insertions(+), 34 deletions(-)

New commits:
commit f14d271d31e75de09821cf1766c7ab2a9c6e0461
Author: Dennis Francis <dennisfrancis.in at gmail.com>
Date:   Wed Jan 20 13:07:38 2016 +0530

    Patch#1 : Dynamic column container in the pursuit of tdf#50916
    
    In this patch dynamic column structure is introduced,
    basically wrapping std::vector<ScColumn*>.
    In ScTable the column container is pre-allocated with
    MAXCOL + 1 columns so that the rest of the code that uses
    need not change for now. So for now the new column
    container will still behave like the static one.
    
    The plan is to *incrementally* modify all instances of
    iterations over columns to make use of the dynamic column
    container and also to address the issues mentioned in the
    thread :
    
    http://nabble.documentfoundation.org/tdf-50916-Calc-Dynamic-column-container-td4162663.html
    
    The final step would be to remove the pre-allocation of the container
    in ScTable constructor and increase of MAXCOLCOUNT
    
    Change-Id: I3ff18cdebc99d8348e06a76f287d1d30279366bd
    Reviewed-on: https://gerrit.libreoffice.org/21620
    Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
    Tested-by: Jenkins <ci at libreoffice.org>

diff --git a/sc/Library_sc.mk b/sc/Library_sc.mk
index d082a6b..f30bf33 100644
--- a/sc/Library_sc.mk
+++ b/sc/Library_sc.mk
@@ -107,6 +107,7 @@ $(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
new file mode 100644
index 0000000..2ce35eb
--- /dev/null
+++ b/sc/inc/colcontainer.hxx
@@ -0,0 +1,88 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+#ifndef INCLUDED_SC_INC_COLCONTAINER_HXX
+#define INCLUDED_SC_INC_COLCONTAINER_HXX
+
+
+#include "types.hxx"
+#include "address.hxx"
+
+#include <vector>
+
+
+class ScColumn;
+class ScDocument;
+class ScColContainer
+{
+public:
+    typedef std::vector<ScColumn*> ScColumnVector;
+private:
+    ScColumnVector    aCols;
+    ScDocument*       pDocument;
+public:
+    ScColContainer( ScDocument* pDoc );
+    ScColContainer( ScDocument* pDoc, const size_t nSize );
+    ~ScColContainer();
+
+    const ScColumn& operator[] ( const size_t nIndex ) const
+    {
+        return *aCols[nIndex];
+    }
+
+    const ScColumn& operator[] ( SCCOL nIndex ) const
+    {
+        return ( *this )[ static_cast<const size_t>( nIndex ) ];
+    }
+
+    const ScColumn& operator[] ( int nIndex ) const
+    {
+        return ( *this )[ static_cast<const size_t>( nIndex ) ];
+    }
+
+    ScColumn& operator[] ( const size_t nIndex )
+    {
+        return *aCols[nIndex];
+    }
+
+    ScColumn& operator[] ( SCCOL nIndex )
+    {
+        return ( *this )[ static_cast<const size_t>( nIndex ) ];
+    }
+
+    ScColumn& operator[] ( int nIndex )
+    {
+        return ( *this )[ static_cast<const size_t>( nIndex ) ];
+    }
+
+    SCCOL size() const
+    {
+        return static_cast<SCCOL>( aCols.size() );
+    }
+
+    void CreateCol( SCCOL nColIdx, SCTAB nTab );
+    void DeleteLastCols( SCSIZE nCols );
+    bool ColumnExists( SCCOL nColIdx ) const;
+    void Clear();
+};
+
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/inc/edittextiterator.hxx b/sc/inc/edittextiterator.hxx
index f1ec1e9..f64b7f4 100644
--- a/sc/inc/edittextiterator.hxx
+++ b/sc/inc/edittextiterator.hxx
@@ -13,7 +13,6 @@
 #include "address.hxx"
 #include "mtvelements.hxx"
 
-class ScColumn;
 class ScTable;
 class ScDocument;
 class EditTextObject;
@@ -29,8 +28,7 @@ namespace sc {
 class EditTextIterator
 {
     const ScTable& mrTable;
-    const ScColumn* mpCol;
-    const ScColumn* mpColEnd;
+    SCCOL mnCol;
     const CellStoreType* mpCells;
     CellStoreType::const_position_type maPos;
     CellStoreType::const_iterator miEnd;
@@ -46,6 +44,10 @@ class EditTextIterator
      */
     void incPos();
     void incBlock();
+    /**
+     * Initialize members w.r.t the dynamic column container in the given table.
+     */
+    void init();
 
 public:
     EditTextIterator( const ScDocument& rDoc, SCTAB nTab );
diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 0e84a70..43a4897 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -26,6 +26,7 @@
 #include <tools/color.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include "column.hxx"
+#include "colcontainer.hxx"
 #include "sortparam.hxx"
 #include "compressedarray.hxx"
 #include "postit.hxx"
@@ -119,7 +120,7 @@ class ScTable : private boost::noncopyable
 private:
     typedef ::std::vector< ScRange > ScRangeVec;
 
-    ScColumn        aCol[MAXCOLCOUNT];
+    ScColContainer  aCol;
 
     OUString aName;
     OUString aCodeName;
diff --git a/sc/source/core/data/colcontainer.cxx b/sc/source/core/data/colcontainer.cxx
new file mode 100644
index 0000000..bbe45fc
--- /dev/null
+++ b/sc/source/core/data/colcontainer.cxx
@@ -0,0 +1,95 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ *
+ * This file incorporates work covered by the following license notice:
+ *
+ *   Licensed to the Apache Software Foundation (ASF) under one or more
+ *   contributor license agreements. See the NOTICE file distributed
+ *   with this work for additional information regarding copyright
+ *   ownership. The ASF licenses this file to you under the Apache
+ *   License, Version 2.0 (the "License"); you may not use this file
+ *   except in compliance with the License. You may obtain a copy of
+ *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
+ */
+
+
+#include "colcontainer.hxx"
+#include "column.hxx"
+#include "document.hxx"
+
+ScColContainer::ScColContainer( ScDocument* pDoc ):
+    aCols( ScColumnVector() ),
+    pDocument( pDoc )
+{}
+
+ScColContainer::ScColContainer( ScDocument* pDoc, const size_t nSize )
+{
+    pDocument = pDoc;
+    aCols.resize( nSize );
+    for ( size_t nCol = 0; nCol < nSize; ++nCol )
+        aCols[nCol] = new ScColumn;
+}
+
+ScColContainer::~ScColContainer()
+{
+    Clear();
+}
+
+void ScColContainer::CreateCol( SCCOL nColIdx, SCTAB nTab )
+{
+    assert( nColIdx >= 0 );
+    SCCOL nSize = size();
+    if ( nColIdx < nSize )
+        return;
+    else
+    {
+        aCols.resize( nColIdx + 1, nullptr );
+        for ( SCCOL nNewColIdx = nSize; nNewColIdx <= nColIdx; ++nNewColIdx )
+        {
+            aCols[nNewColIdx] = new ScColumn;
+            aCols[nNewColIdx]->Init( nNewColIdx, nTab, pDocument );
+            // TODO: Apply any full row formatting / document formatting
+        }
+    }
+}
+
+void ScColContainer::DeleteLastCols( SCSIZE nCols )
+{
+    SCCOL nSize = size();
+    SCCOL nFirstColToDelete = nSize - nCols;
+    if ( !ColumnExists( nFirstColToDelete ) )
+        return;
+
+    for ( SCCOL nColToDelete = nFirstColToDelete; nColToDelete < nSize; ++nColToDelete )
+    {
+        if ( !pDocument->IsInDtorClear() )
+            aCols[nColToDelete]->FreeNotes();
+        aCols[nColToDelete]->PrepareBroadcastersForDestruction();
+        delete aCols[nColToDelete];
+        aCols.resize( static_cast<size_t>( nFirstColToDelete ) );
+    }
+}
+
+bool ScColContainer::ColumnExists( SCCOL nColIdx ) const
+{
+    if ( nColIdx < 0 || nColIdx >= size() )
+        return false;
+    return true;
+}
+
+void ScColContainer::Clear()
+{
+    SCCOL nSize = size();
+    for ( SCCOL nIdx = 0; nIdx < nSize; ++nIdx )
+    {
+        aCols[nIdx]->PrepareBroadcastersForDestruction();
+        delete aCols[nIdx];
+    }
+    aCols.clear();
+}
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index 14dfef5..49243d8 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -593,10 +593,9 @@ void ScDocumentImport::finalize()
             continue;
 
         ScTable& rTab = **itTab;
-        ScColumn* pCol = &rTab.aCol[0];
-        ScColumn* pColEnd = pCol + static_cast<size_t>(MAXCOLCOUNT);
-        for (; pCol != pColEnd; ++pCol)
-            initColumn(*pCol);
+        SCCOL nNumCols = rTab.aCol.size();
+        for (SCCOL nColIdx = 0; nColIdx < nNumCols; ++nColIdx)
+            initColumn(rTab.aCol[nColIdx]);
     }
 }
 
diff --git a/sc/source/core/data/edittextiterator.cxx b/sc/source/core/data/edittextiterator.cxx
index 778ef2b..c689ebc 100644
--- a/sc/source/core/data/edittextiterator.cxx
+++ b/sc/source/core/data/edittextiterator.cxx
@@ -16,12 +16,26 @@ namespace sc {
 
 EditTextIterator::EditTextIterator( const ScDocument& rDoc, SCTAB nTab ) :
     mrTable(*rDoc.maTabs.at(nTab)),
-    mpCol(&mrTable.aCol[0]),
-    mpColEnd(mpCol + static_cast<size_t>(MAXCOLCOUNT)),
-    mpCells(&mpCol->maCells),
-    maPos(mpCells->position(0)),
-    miEnd(mpCells->end())
+    mnCol(0),
+    mpCells(nullptr),
+    maPos(sc::CellStoreType::const_position_type()),
+    miEnd(maPos.first)
 {
+    init();
+}
+
+void EditTextIterator::init()
+{
+    mnCol = 0;
+    if (mnCol >= mrTable.aCol.size())
+        mnCol = -1;
+
+    if (mnCol != -1)
+    {
+        mpCells = &mrTable.aCol[mnCol].maCells;
+        maPos = mpCells->position(0);
+        miEnd = mpCells->end();
+    }
 }
 
 const EditTextObject* EditTextIterator::seek()
@@ -32,12 +46,12 @@ const EditTextObject* EditTextIterator::seek()
         if (maPos.first == miEnd)
         {
             // Move to the next column.
-            ++mpCol;
-            if (mpCol == mpColEnd)
+            ++mnCol;
+            if (mnCol >= mrTable.aCol.size())
                 // No more columns.
                 return nullptr;
 
-            mpCells = &mpCol->maCells;
+            mpCells = &mrTable.aCol[mnCol].maCells;
             maPos = mpCells->position(0);
             miEnd = mpCells->end();
         }
@@ -64,16 +78,17 @@ void EditTextIterator::incBlock()
 
 const EditTextObject* EditTextIterator::first()
 {
-    mpCol = &mrTable.aCol[0];
-    mpColEnd = mpCol + static_cast<size_t>(MAXCOLCOUNT);
-    mpCells = &mpCol->maCells;
-    maPos = mpCells->position(0);
-    miEnd = mpCells->end();
+    init();
+    if (mnCol == -1)
+        return nullptr;
     return seek();
 }
 
 const EditTextObject* EditTextIterator::next()
 {
+    if (mnCol == -1)
+        return nullptr;
+
     if (maPos.first == miEnd)
         return nullptr;
 
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 2bc2705..355d6d0 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -81,7 +81,7 @@ ScProgress* GetProgressBar(
 }
 
 void GetOptimalHeightsInColumn(
-    sc::RowHeightContext& rCxt, ScColumn* pCol, SCROW nStartRow, SCROW nEndRow,
+    sc::RowHeightContext& rCxt, ScColContainer& rCol, SCROW nStartRow, SCROW nEndRow,
     ScProgress* pProgress, sal_uInt32 nProgressStart )
 {
     assert(nStartRow <= nEndRow);
@@ -94,7 +94,7 @@ void GetOptimalHeightsInColumn(
 
     std::vector<sal_uInt16>& rHeights = rCxt.getHeightArray();
 
-    pCol[MAXCOL].GetOptimalHeight(rCxt, nStartRow, nEndRow, 0, 0);
+    rCol[MAXCOL].GetOptimalHeight(rCxt, nStartRow, nEndRow, 0, 0);
 
     //  from there search for the standard height that is in use in the lower part
 
@@ -107,11 +107,11 @@ void GetOptimalHeightsInColumn(
     sal_uLong nWeightedCount = 0;
     for (SCCOL nCol=0; nCol<MAXCOL; nCol++)     // MAXCOL already above
     {
-        pCol[nCol].GetOptimalHeight(rCxt, nStartRow, nEndRow, nMinHeight, nMinStart);
+        rCol[nCol].GetOptimalHeight(rCxt, nStartRow, nEndRow, nMinHeight, nMinStart);
 
         if (pProgress)
         {
-            sal_uLong nWeight = pCol[nCol].GetWeightedCount();
+            sal_uLong nWeight = rCol[nCol].GetWeightedCount();
             if (nWeight)        // does not have to be the same Status
             {
                 nWeightedCount += nWeight;
@@ -227,6 +227,7 @@ bool SetOptimalHeightsToRows(
 
 ScTable::ScTable( ScDocument* pDoc, SCTAB nNewTab, const OUString& rNewName,
                     bool bColInfo, bool bRowInfo ) :
+    aCol( pDoc, MAXCOLCOUNT ),
     aName( rNewName ),
     aCodeName( rNewName ),
     nLinkRefreshDelay( 0 ),
@@ -349,9 +350,6 @@ ScTable::~ScTable()
     delete mpRangeName;
     delete pDBDataNoName;
     DestroySortCollator();
-
-    for (SCCOL k=0; k<=MAXCOL; k++)
-        aCol[k].PrepareBroadcastersForDestruction();
 }
 
 void ScTable::GetName( OUString& rName ) const
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 11c0d58..a47cb9b 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -67,16 +67,16 @@ namespace {
 
 class ColumnRegroupFormulaCells
 {
-    ScColumn* mpCols;
+    ScColContainer& mrCols;
     std::vector<ScAddress>* mpGroupPos;
 
 public:
-    ColumnRegroupFormulaCells( ScColumn* pCols, std::vector<ScAddress>* pGroupPos ) :
-        mpCols(pCols), mpGroupPos(pGroupPos) {}
+    ColumnRegroupFormulaCells( ScColContainer& rCols, std::vector<ScAddress>* pGroupPos ) :
+        mrCols(rCols), mpGroupPos(pGroupPos) {}
 
     void operator() (SCCOL nCol)
     {
-        mpCols[nCol].RegroupFormulaCells(mpGroupPos);
+        mrCols[nCol].RegroupFormulaCells(mpGroupPos);
     }
 };
 
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 2713992..828f0a8 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -414,7 +414,7 @@ public:
 namespace {
 
 void initDataRows(
-    ScSortInfoArray& rArray, ScTable& rTab, ScColumn* pCols,
+    ScSortInfoArray& rArray, ScTable& rTab, ScColContainer& rCols,
     SCCOL nCol1, SCROW nRow1, SCCOL nCol2, SCROW nRow2,
     bool bPattern, bool bHiddenFiltered )
 {
@@ -423,7 +423,7 @@ void initDataRows(
 
     for (SCCOL nCol = nCol1; nCol <= nCol2; ++nCol)
     {
-        ScColumn& rCol = pCols[nCol];
+        ScColumn& rCol = rCols[nCol];
 
         // Skip reordering of cell formats if the whole span is on the same pattern entry.
         bool bUniformPattern = rCol.GetPatternCount(nRow1, nRow2) < 2u;


More information about the Libreoffice-commits mailing list