[Libreoffice-commits] core.git: Branch 'feature/formula-core-rework' - sc/inc sc/source

Michael Meeks michael.meeks at suse.com
Tue Mar 19 06:21:10 PDT 2013


 sc/inc/column.hxx               |   13 +++++++
 sc/source/core/data/cell2.cxx   |   34 +++++++++----------
 sc/source/core/data/column.cxx  |    1 
 sc/source/core/data/column3.cxx |   71 ++++++++++++++++++++++++++++++++++++----
 4 files changed, 94 insertions(+), 25 deletions(-)

New commits:
commit a53c3df6139c2421f873e438a3e7a3752c1f2df6
Author: Michael Meeks <michael.meeks at suse.com>
Date:   Tue Mar 19 12:56:51 2013 +0000

    build spans of doubles and cleanup excessive debug.
    
    Change-Id: Ib76596cae12c87825118903cc61b12c251f0c1b7

diff --git a/sc/inc/column.hxx b/sc/inc/column.hxx
index 18543f0..4776a70 100644
--- a/sc/inc/column.hxx
+++ b/sc/inc/column.hxx
@@ -25,6 +25,7 @@
 #include "address.hxx"
 #include "rangenam.hxx"
 #include "types.hxx"
+#include <boost/intrusive_ptr.hpp>
 
 #include <set>
 #include <vector>
@@ -71,6 +72,8 @@ class ScFlatBoolRowSegments;
 struct ScSetStringParam;
 struct ScColWidthParam;
 class ScColumnTextWidthIterator;
+class ScFormulaCellGroup;
+typedef ::boost::intrusive_ptr<ScFormulaCellGroup> ScFormulaCellGroupRef;
 
 struct ScNeededSizeOptions
 {
@@ -89,6 +92,12 @@ struct ColEntry
     ScBaseCell* pCell;
 };
 
+struct ColDoubleEntry
+{
+    SCROW               mnStart;
+    std::vector<double> maData;
+};
+
 class ScColumn
 {
     typedef mdds::multi_type_vector<mdds::mtv::element_block_func> TextWidthType;
@@ -109,6 +118,10 @@ class ScColumn
 
     std::vector<ColEntry> maItems;
 
+    // temporary until we switch to mdds container
+    std::vector<ColDoubleEntry *> maDoubles;
+    std::vector<ScFormulaCellGroupRef> maFnGroups;
+
     ScAttrArray*          pAttrArray;
     ScDocument*           pDocument;
     bool                  bDirtyGroups;     /// formula groups are dirty.
diff --git a/sc/source/core/data/cell2.cxx b/sc/source/core/data/cell2.cxx
index f450f75..ca21710 100644
--- a/sc/source/core/data/cell2.cxx
+++ b/sc/source/core/data/cell2.cxx
@@ -1733,15 +1733,12 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
 
     if ( !pThis || !pOther )
     {
-        fprintf( stderr, "no compiled code for cells !" );
+        fprintf( stderr, "Error: no compiled code for cells !" );
         return NULL;
     }
 
     if ( pThisLen != pOtherLen )
-    {
-        fprintf( stderr, "different length formulae !" );
         return NULL;
-    }
 
     // check we are basically the same function
     for ( sal_uInt16 i = 0; i < pThisLen; i++ )
@@ -1750,7 +1747,7 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
              pThis[ i ]->GetOpCode() != pOther[ i ]->GetOpCode() ||
              pThis[ i ]->GetParamCount() != pOther[ i ]->GetParamCount() )
         {
-            fprintf( stderr, "Incompatible type, op-code or param counts\n" );
+//            fprintf( stderr, "Incompatible type, op-code or param counts\n" );
             return NULL;
         }
         switch( pThis[ i ]->GetType() )
@@ -1758,32 +1755,33 @@ ScSimilarFormulaDelta *ScFormulaCell::BuildDeltaTo( ScFormulaCell *pOtherCell )
         case formula::svMatrix:
         case formula::svExternalSingleRef:
         case formula::svExternalDoubleRef:
-            fprintf( stderr, "Ignoring matrix and external references for now\n" );
+//            fprintf( stderr, "Ignoring matrix and external references for now\n" );
             return NULL;
         default:
             break;
         }
     }
 
-    fprintf( stderr, "matching formulae !\n" );
     ScSimilarFormulaDelta *pDelta = new ScSimilarFormulaDelta();
 
     for ( sal_uInt16 i = 0; i < pThisLen; i++ )
     {
-        if ( pThis[i]->GetType() != formula::svSingleRef &&
-             pThis[i]->GetType() != formula::svDoubleRef )
-            continue;
-
         ScToken *pThisTok = static_cast< ScToken * >( pThis[ i ] );
         ScToken *pOtherTok = static_cast< ScToken * >( pOther[ i ] );
 
-        const ScSingleRefData& aThisRef = pThisTok->GetSingleRef();
-        const ScSingleRefData& aOtherRef = pOtherTok->GetSingleRef();
-        pDelta->push_delta( aThisRef, aOtherRef );
-
-        const ScSingleRefData& aThisRef2 = pThisTok->GetSingleRef2();
-        const ScSingleRefData& aOtherRef2 = pOtherTok->GetSingleRef2();
-        pDelta->push_delta( aThisRef2, aOtherRef2 );
+        if ( pThis[i]->GetType() == formula::svSingleRef ||
+             pThis[i]->GetType() == formula::svDoubleRef )
+        {
+            const ScSingleRefData& aThisRef = pThisTok->GetSingleRef();
+            const ScSingleRefData& aOtherRef = pOtherTok->GetSingleRef();
+            pDelta->push_delta( aThisRef, aOtherRef );
+        }
+        if ( pThis[i]->GetType() == formula::svDoubleRef )
+        {
+            const ScSingleRefData& aThisRef2 = pThisTok->GetSingleRef2();
+            const ScSingleRefData& aOtherRef2 = pOtherTok->GetSingleRef2();
+            pDelta->push_delta( aThisRef2, aOtherRef2 );
+        }
     }
 
     return pDelta;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 4853fe94..ee38f0f 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -2022,7 +2022,6 @@ void ScColumn::UpdateCompile( bool bForceIfNameInUse )
 {
     if ( !maItems.empty() )
     {
-        fprintf( stderr, "UpdateCompile - column !?\n" );
         for (SCSIZE i = 0; i < maItems.size(); i++)
         {
             ScFormulaCell* p = (ScFormulaCell*) maItems[i].pCell;
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx
index 6ee4495..f702b25 100644
--- a/sc/source/core/data/column3.cxx
+++ b/sc/source/core/data/column3.cxx
@@ -2014,6 +2014,12 @@ void ScColumn::RebuildFormulaGroups()
     if ( maItems.empty() || !bDirtyGroups )
         return;
 
+    // clear double groups
+    for (std::vector< ColDoubleEntry *>::iterator it = maDoubles.begin();
+         it != maDoubles.end(); ++it )
+        delete *it;
+    maDoubles.clear();
+
     // clear previous groups
     ScFormulaCellGroupRef xNone;
     for (size_t i = 0; i < maItems.size(); i++)
@@ -2024,21 +2030,42 @@ void ScColumn::RebuildFormulaGroups()
     }
 
     // re-build groups
+    ColDoubleEntry *pLastDouble = NULL;
     for (size_t i = 1; i < maItems.size(); i++)
     {
         ColEntry &rCur = maItems[ i ];
         ColEntry &rPrev = maItems[ i - 1 ];
-        if ( ( rPrev.nRow != rCur.nRow - 1 ) ||               // not contiguous
-             !rCur.pCell || !rPrev.pCell ||                   // paranoia
-             rCur.pCell->GetCellType() != CELLTYPE_FORMULA || // not formulae
-             rPrev.pCell->GetCellType() != CELLTYPE_FORMULA )
+        if ( ( rPrev.nRow != rCur.nRow - 1 ) ||                        // not contiguous
+             !rCur.pCell || !rPrev.pCell ||                            // paranoia
+             rCur.pCell->GetCellType() != rPrev.pCell->GetCellType() ) // same type
+        {
+            pLastDouble = NULL;
+            continue;
+        }
+
+        // collate doubles
+        if ( rCur.pCell->GetCellType() == CELLTYPE_VALUE )
+        {
+            if ( !pLastDouble )
+            {
+                pLastDouble = new ColDoubleEntry();
+                pLastDouble->mnStart = i - 1;
+                pLastDouble->maData.push_back(
+                        static_cast< ScValueCell * >( rPrev.pCell )->GetValue() );
+                maDoubles.push_back( pLastDouble );
+            }
+            pLastDouble->maData.push_back(
+                        static_cast< ScValueCell * >( rCur.pCell )->GetValue() );
+            continue;
+        }
+
+        if ( rCur.pCell->GetCellType() != CELLTYPE_FORMULA )
             continue;
 
         // see if these formulae are similar
         ScFormulaCell *pCur = static_cast< ScFormulaCell *>( rCur.pCell );
         ScFormulaCell *pPrev = static_cast< ScFormulaCell *>( rPrev.pCell );
 
-        fprintf( stderr, "column has contiguous formulae\n" );
         ScSimilarFormulaDelta *pDelta = pPrev->BuildDeltaTo( pCur );
 
         if ( !pDelta )
@@ -2058,6 +2085,8 @@ void ScColumn::RebuildFormulaGroups()
             pGroup->mnLength = 2;
 
             xGroup.reset( pGroup );
+            maFnGroups.push_back( xGroup );
+
             pCur->SetCellGroup( xGroup );
             pPrev->SetCellGroup( xGroup );
         }
@@ -2070,6 +2099,7 @@ void ScColumn::RebuildFormulaGroups()
         }
         else
         {
+#if OSL_DEBUG_LEVEL > 1
             OUString aFormula;
             pCur->GetFormula( aFormula );
             ScAddress aAddr( nCol, rCur.nRow, nTab );
@@ -2079,11 +2109,40 @@ void ScColumn::RebuildFormulaGroups()
             fprintf( stderr, "unusual incompatible extension in cell '%s' of formulae '%s'\n" ,
                      OUStringToOString( aCellAddr, RTL_TEXTENCODING_UTF8 ).getStr(),
                      OUStringToOString( aFormula, RTL_TEXTENCODING_UTF8 ).getStr() );
-
+#endif
             pCur->ReleaseDelta( pDelta );
         }
     }
 
+#if 1 // OSL_DEBUG_LEVEL > 0
+    if ( maDoubles.size() + maFnGroups.size() > 0 )
+    {
+        rtl::OUString aStr;
+        fprintf( stderr, "column %2d has %2d double span(s): ", (int)nCol, (int)maDoubles.size() );
+        for (std::vector< ColDoubleEntry *>::iterator it = maDoubles.begin();
+             it != maDoubles.end(); ++it )
+        {
+            ScRange aDoubleRange( nCol, (*it)->mnStart, nTab,
+                                  nCol, (*it)->mnStart + (*it)->maData.size() - 1, nTab );
+            aDoubleRange.Format( aStr, SCA_VALID | SCA_VALID_COL | SCA_VALID_ROW, pDocument );
+            fprintf( stderr, "%s, ", OUStringToOString( aStr, RTL_TEXTENCODING_UTF8 ).getStr() );
+        }
+        fprintf( stderr, "\n" );
+
+        fprintf( stderr, "column %2d has %2d formula span(s): ", (int)nCol, (int)maFnGroups.size() );
+        for (std::vector< ScFormulaCellGroupRef>::iterator it = maFnGroups.begin();
+             it != maFnGroups.end(); ++it )
+        {
+            ScRange aDoubleRange( nCol, (*it)->mnStart, nTab,
+                                  nCol, (*it)->mnStart + (*it)->mnLength - 1, nTab );
+            aDoubleRange.Format( aStr, SCA_VALID | SCA_VALID_COL | SCA_VALID_ROW, pDocument );
+            fprintf( stderr, "%s, ", OUStringToOString( aStr, RTL_TEXTENCODING_UTF8 ).getStr() );
+        }
+        fprintf( stderr, "\n" );
+    }
+#endif
+
+
     bDirtyGroups = false;
 }
 


More information about the Libreoffice-commits mailing list