[Libreoffice-commits] .: Branch 'feature/new-autofilter-popup' - 2 commits - sc/inc sc/source

Kohei Yoshida kohei at kemper.freedesktop.org
Fri Nov 4 11:35:56 PDT 2011


 sc/inc/table.hxx               |    6 +-
 sc/source/core/data/table2.cxx |    6 +-
 sc/source/core/data/table3.cxx |   87 ++++++++++++++++++++++++++---------------
 3 files changed, 62 insertions(+), 37 deletions(-)

New commits:
commit 86ef266044cf804ce64e43e82cec115d3021c8c6
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Fri Nov 4 14:35:39 2011 -0400

    Extracted complex if conditions into own methods. Much more readable.

diff --git a/sc/inc/table.hxx b/sc/inc/table.hxx
index 9cd3c57..0304f68 100644
--- a/sc/inc/table.hxx
+++ b/sc/inc/table.hxx
@@ -435,9 +435,9 @@ public:
 
     void        LimitChartArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow );
 
-    bool        HasData( SCCOL nCol, SCROW nRow );
-    bool        HasStringData( SCCOL nCol, SCROW nRow );
-    bool        HasValueData( SCCOL nCol, SCROW nRow );
+    bool        HasData( SCCOL nCol, SCROW nRow ) const;
+    bool        HasStringData( SCCOL nCol, SCROW nRow ) const;
+    bool        HasValueData( SCCOL nCol, SCROW nRow ) const;
     bool        HasStringCells( SCCOL nStartCol, SCROW nStartRow,
                                 SCCOL nEndCol, SCROW nEndRow ) const;
 
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index 6b18359..451a265 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -1184,7 +1184,7 @@ void ScTable::GetLastDataPos(SCCOL& rCol, SCROW& rRow) const
 }
 
 
-bool ScTable::HasData( SCCOL nCol, SCROW nRow )
+bool ScTable::HasData( SCCOL nCol, SCROW nRow ) const
 {
     if (ValidColRow(nCol,nRow))
         return aCol[nCol].HasDataAt( nRow );
@@ -1193,7 +1193,7 @@ bool ScTable::HasData( SCCOL nCol, SCROW nRow )
 }
 
 
-bool ScTable::HasStringData( SCCOL nCol, SCROW nRow )
+bool ScTable::HasStringData( SCCOL nCol, SCROW nRow ) const
 {
     if (ValidColRow(nCol,nRow))
         return aCol[nCol].HasStringData( nRow );
@@ -1202,7 +1202,7 @@ bool ScTable::HasStringData( SCCOL nCol, SCROW nRow )
 }
 
 
-bool ScTable::HasValueData( SCCOL nCol, SCROW nRow )
+bool ScTable::HasValueData( SCCOL nCol, SCROW nRow ) const
 {
     if (ValidColRow(nCol,nRow))
         return aCol[nCol].HasValueData( nRow );
diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index 6153474..e4c7597 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1064,6 +1064,46 @@ bool ScTable::DoSubTotals( ScSubTotalParam& rParam )
     return bSpaceLeft;
 }
 
+namespace {
+
+bool isQueryByValue(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRow, const ScBaseCell* pCell)
+{
+    if (rEntry.bQueryByString)
+        return false;
+
+    if (pCell)
+        return pCell->HasValueData();
+
+    return rTable.HasValueData(static_cast<SCCOL>(rEntry.nField), nRow);
+}
+
+bool isQueryByString(const ScTable& rTable, const ScQueryEntry& rEntry, SCROW nRow, const ScBaseCell* pCell)
+{
+    switch (rEntry.eOp)
+    {
+        case SC_EQUAL:
+        case SC_NOT_EQUAL:
+        case SC_CONTAINS:
+        case SC_DOES_NOT_CONTAIN:
+        case SC_BEGINS_WITH:
+        case SC_ENDS_WITH:
+        case SC_DOES_NOT_BEGIN_WITH:
+        case SC_DOES_NOT_END_WITH:
+            return true;
+        default:
+            ;
+    }
+
+    if (!rEntry.bQueryByString)
+        return false;
+
+    if (pCell)
+        return pCell->HasStringData();
+
+    return rTable.HasStringData(static_cast<SCCOL>(rEntry.nField), nRow);
+}
+
+}
 
 bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
         bool* pSpecial /* =NULL */ , ScBaseCell* pCell /* =NULL */ ,
@@ -1103,9 +1143,8 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
             else // if (rEntry.nVal == SC_NONEMPTYFIELDS)
                 bOk = aCol[rEntry.nField].HasDataAt( nRow );
         }
-        else if ( !rEntry.bQueryByString && (pCell ? pCell->HasValueData() :
-                    HasValueData( static_cast<SCCOL>(rEntry.nField), nRow)))
-        {   // by Value
+        else if (isQueryByValue(*this, rEntry, nRow, pCell))
+        {
             double nCellVal;
             if ( pCell )
             {
@@ -1183,15 +1222,8 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
                 }
             }
         }
-        else if ( (rEntry.eOp == SC_EQUAL || rEntry.eOp == SC_NOT_EQUAL) ||
-                  (rEntry.eOp == SC_CONTAINS || rEntry.eOp == SC_DOES_NOT_CONTAIN ||
-                   rEntry.eOp == SC_BEGINS_WITH || rEntry.eOp == SC_ENDS_WITH ||
-                   rEntry.eOp == SC_DOES_NOT_BEGIN_WITH || rEntry.eOp == SC_DOES_NOT_END_WITH) ||
-                (rEntry.bQueryByString && (pCell ? pCell->HasStringData() :
-                                           HasStringData(
-                                               static_cast<SCCOL>(rEntry.nField),
-                                               nRow))))
-        {   // by String
+        else if (isQueryByString(*this, rEntry, nRow, pCell))
+        {
             String  aCellStr;
             if( rEntry.eOp == SC_CONTAINS || rEntry.eOp == SC_DOES_NOT_CONTAIN
                 || rEntry.eOp == SC_BEGINS_WITH || rEntry.eOp == SC_ENDS_WITH
commit 0572e4c660f2cdedf0cde5a4278622b291035769
Author: Kohei Yoshida <kohei.yoshida at suse.com>
Date:   Fri Nov 4 14:10:30 2011 -0400

    Prefer STL over heap array.

diff --git a/sc/source/core/data/table3.cxx b/sc/source/core/data/table3.cxx
index ec9657f..6153474 100644
--- a/sc/source/core/data/table3.cxx
+++ b/sc/source/core/data/table3.cxx
@@ -1074,12 +1074,9 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
 
     //---------------------------------------------------------------
 
-    const SCSIZE nFixedBools = 32;
-    bool aBool[nFixedBools];
-    bool aTest[nFixedBools];
     SCSIZE nEntryCount = rParam.GetEntryCount();
-    bool* pPasst = ( nEntryCount <= nFixedBools ? &aBool[0] : new bool[nEntryCount] );
-    bool* pTest = ( nEntryCount <= nFixedBools ? &aTest[0] : new bool[nEntryCount] );
+    std::vector<bool> aPassed(nEntryCount, false);
+    std::vector<bool> aTestEqual(nEntryCount, false);
 
     long    nPos = -1;
     SCSIZE  i    = 0;
@@ -1386,21 +1383,21 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
         if (nPos == -1)
         {
             nPos++;
-            pPasst[nPos] = bOk;
-            pTest[nPos] = bTestEqual;
+            aPassed[nPos] = bOk;
+            aTestEqual[nPos] = bTestEqual;
         }
         else
         {
             if (rEntry.eConnect == SC_AND)
             {
-                pPasst[nPos] = pPasst[nPos] && bOk;
-                pTest[nPos] = pTest[nPos] && bTestEqual;
+                aPassed[nPos] = aPassed[nPos] && bOk;
+                aTestEqual[nPos] = aTestEqual[nPos] && bTestEqual;
             }
             else
             {
                 nPos++;
-                pPasst[nPos] = bOk;
-                pTest[nPos] = bTestEqual;
+                aPassed[nPos] = bOk;
+                aTestEqual[nPos] = bTestEqual;
             }
         }
         i++;
@@ -1408,17 +1405,13 @@ bool ScTable::ValidQuery(SCROW nRow, const ScQueryParam& rParam,
 
     for ( long j=1; j <= nPos; j++ )
     {
-        pPasst[0] = pPasst[0] || pPasst[j];
-        pTest[0] = pTest[0] || pTest[j];
+        aPassed[0] = aPassed[0] || aPassed[j];
+        aTestEqual[0] = aTestEqual[0] || aTestEqual[j];
     }
 
-    bool bRet = pPasst[0];
-    if ( pPasst != &aBool[0] )
-        delete [] pPasst;
+    bool bRet = aPassed[0];
     if ( pbTestEqualCondition )
-        *pbTestEqualCondition = pTest[0];
-    if ( pTest != &aTest[0] )
-        delete [] pTest;
+        *pbTestEqualCondition = aTestEqual[0];
 
     return bRet;
 }


More information about the Libreoffice-commits mailing list