[Libreoffice-commits] core.git: Branch 'feature/fixes36' - sc/source

Kohei Yoshida kohei.yoshida at collabora.com
Thu Oct 13 12:25:06 UTC 2016


 sc/source/core/inc/interpre.hxx  |   12 ++++
 sc/source/core/tool/interpr1.cxx |  101 ++++++++++++++++++---------------------
 2 files changed, 58 insertions(+), 55 deletions(-)

New commits:
commit ab3f76d5aef497e67ecc072117a9bc2a939388b2
Author: Kohei Yoshida <kohei.yoshida at collabora.com>
Date:   Wed Oct 12 20:29:34 2016 -0400

    Remove the branching at the end of IterateParametersIfs().
    
    For (hopefully) better performance.
    
    Change-Id: I59ed454aa9ace2f945facceee14f4e25610feebf

diff --git a/sc/source/core/inc/interpre.hxx b/sc/source/core/inc/interpre.hxx
index a01b60b..4fe6e56 100644
--- a/sc/source/core/inc/interpre.hxx
+++ b/sc/source/core/inc/interpre.hxx
@@ -39,6 +39,7 @@
 #include <map>
 #include <memory>
 #include <vector>
+#include <limits>
 
 class ScDocument;
 class SbxVariable;
@@ -62,6 +63,15 @@ struct RangeMatrix;
 struct Compare;
 struct CompareOptions;
 
+struct ParamIfsResult
+{
+    double mfSum = 0.0;
+    double mfMem = 0.0;
+    double mfCount = 0.0;
+    double mfMin = std::numeric_limits<double>::max();
+    double mfMax = std::numeric_limits<double>::min();
+};
+
 }
 
 namespace svl {
@@ -555,7 +565,7 @@ double IterateParametersIf( ScIterFuncIf );
 void ScCountIf();
 void ScSumIf();
 void ScAverageIf();
-double IterateParametersIfs( ScIterFuncIfs );
+void IterateParametersIfs( sc::ParamIfsResult& rRes );
 void ScSumIfs();
 void ScAverageIfs();
 void ScCountIfs();
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index 239bb74..532783c 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -5311,7 +5311,7 @@ void ScInterpreter::ScCountIf()
     }
 }
 
-double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
+void ScInterpreter::IterateParametersIfs( sc::ParamIfsResult& rRes )
 {
     sal_uInt8 nParamCount = GetByte();
     sal_uInt8 nQueryCount = nParamCount / 2;
@@ -5320,12 +5320,6 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
     size_t nRowSize = 0;
     size_t nColSize = 0;
     double fVal = 0.0;
-    double fSum = 0.0;
-    double fMem = 0.0;
-    double fRes = 0.0;
-    double fCount = 0.0;
-    double fMin = std::numeric_limits<double>::max();
-    double fMax = std::numeric_limits<double>::min();
     short nParam = 1;
     size_t nRefInList = 0;
     SCCOL nDimensionCols = 0;
@@ -5344,7 +5338,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                 {
                     ScAddress aAdr;
                     if ( !PopDoubleRefOrSingleRef( aAdr ) )
-                        return 0;
+                        return;
 
                     ScRefCellValue aCell(*pDok, aAdr);
                     switch (aCell.meType)
@@ -5406,7 +5400,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
         }
 
         if (nGlobalError)
-            return 0;   // and bail out, no need to evaluate other arguments
+            return;   // and bail out, no need to evaluate other arguments
 
         // take range
         nParam = 1;
@@ -5444,7 +5438,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                     if (!pQueryMatrix)
                     {
                         SetError( errIllegalParameter);
-                        return 0;
+                        return;
                     }
                     nCol1 = 0;
                     nRow1 = 0;
@@ -5458,12 +5452,12 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                 break;
             default:
                 SetError( errIllegalParameter);
-                return 0;
+                return;
         }
         if ( nTab1 != nTab2 )
         {
             SetError( errIllegalArgument);
-            return 0;
+            return;
         }
 
         // All reference ranges must be of same dimension and size.
@@ -5474,12 +5468,12 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
         if ((nDimensionCols != (nCol2 - nCol1 + 1)) || (nDimensionRows != (nRow2 - nRow1 + 1)))
         {
             SetError ( errIllegalArgument);
-            return 0;
+            return;
         }
 
         // recalculate matrix values
         if (nGlobalError)
-            return 0;
+            return;
 
         // initialize temporary result matrix
         if (aResArray.empty())
@@ -5523,7 +5517,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
             if (nGlobalError || !pResultMatrix)
             {
                 SetError( errIllegalParameter);
-                return 0;
+                return;
             }
 
             // result matrix is filled with boolean values.
@@ -5532,7 +5526,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
             if (aResArray.size() != aResValues.size())
             {
                 SetError( errIllegalParameter);
-                return 0;
+                return;
             }
 
             std::vector<sal_uInt8>::iterator itRes = aResArray.begin(), itResEnd = aResArray.end();
@@ -5559,7 +5553,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
     }
 
     if (nGlobalError)
-        return 0;   // bail out
+        return;   // bail out
 
     // main range - only for AVERAGEIFS, SUMIFS, MINIFS and MAXIFS
     if (nParamCount == 1)
@@ -5600,7 +5594,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                     if (!pMainMatrix)
                     {
                         SetError( errIllegalParameter);
-                        return 0;
+                        return;
                     }
                     nMainCol1 = 0;
                     nMainRow1 = 0;
@@ -5614,23 +5608,23 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                 break;
             default:
                 SetError( errIllegalParameter);
-                return 0;
+                return;
         }
         if ( nMainTab1 != nMainTab2 )
         {
             SetError( errIllegalArgument);
-            return 0;
+            return;
         }
 
         // All reference ranges must be of same dimension and size.
         if ((nDimensionCols != (nMainCol2 - nMainCol1 + 1)) || (nDimensionRows != (nMainRow2 - nMainRow1 + 1)))
         {
             SetError ( errIllegalArgument);
-            return 0;
+            return;
         }
 
         if (nGlobalError)
-            return 0;   // bail out
+            return;   // bail out
 
         // end-result calculation
         ScAddress aAdr;
@@ -5642,7 +5636,7 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
             if (aResArray.size() != aMainValues.size())
             {
                 SetError( errIllegalArgument);
-                return 0;
+                return;
             }
 
             std::vector<sal_uInt8>::const_iterator itRes = aResArray.begin(), itResEnd = aResArray.end();
@@ -5656,18 +5650,18 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                 if (GetDoubleErrorValue(fVal) == errElementNaN)
                     continue;
 
-                ++fCount;
+                ++rRes.mfCount;
                 if (bNull && fVal != 0.0)
                 {
                     bNull = false;
-                    fMem = fVal;
+                    rRes.mfMem = fVal;
                 }
                 else
-                    fSum += fVal;
-                if ( fMin > fVal )
-                    fMin = fVal;
-                if ( fMax < fVal )
-                    fMax = fVal;
+                    rRes.mfSum += fVal;
+                if ( rRes.mfMin > fVal )
+                    rRes.mfMin = fVal;
+                if ( rRes.mfMax < fVal )
+                    rRes.mfMax = fVal;
             }
         }
         else
@@ -5685,18 +5679,18 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
                         if (aCell.hasNumeric())
                         {
                             fVal = GetCellValue(aAdr, aCell);
-                            ++fCount;
+                            ++rRes.mfCount;
                             if ( bNull && fVal != 0.0 )
                             {
                                 bNull = false;
-                                fMem = fVal;
+                                rRes.mfMem = fVal;
                             }
                             else
-                                fSum += fVal;
-                            if ( fMin > fVal )
-                                fMin = fVal;
-                            if ( fMax < fVal )
-                                fMax = fVal;
+                                rRes.mfSum += fVal;
+                            if ( rRes.mfMin > fVal )
+                                rRes.mfMin = fVal;
+                            if ( rRes.mfMax < fVal )
+                                rRes.mfMax = fVal;
                         }
                     }
                 }
@@ -5708,19 +5702,8 @@ double ScInterpreter::IterateParametersIfs( ScIterFuncIfs eFunc )
         std::vector<sal_uInt8>::const_iterator itRes = aResArray.begin(), itResEnd = aResArray.end();
         for (; itRes != itResEnd; ++itRes)
             if (*itRes == nQueryCount)
-                ++fCount;
+                ++rRes.mfCount;
     }
-
-    switch( eFunc )
-    {
-        case ifSUMIFS:     fRes = ::rtl::math::approxAdd( fSum, fMem ); break;
-        case ifAVERAGEIFS: fRes = div( ::rtl::math::approxAdd( fSum, fMem ), fCount); break;
-        case ifCOUNTIFS:   fRes = fCount; break;
-        case ifMINIFS:     fRes = ( fMin < std::numeric_limits<double>::max() ? fMin : 0 ); break;
-        case ifMAXIFS:     fRes = ( fMax > std::numeric_limits<double>::min() ? fMax : 0 ); break;
-        default: ; // nothing
-    }
-    return fRes;
 }
 
 void ScInterpreter::ScSumIfs()
@@ -5733,7 +5716,9 @@ void ScInterpreter::ScSumIfs()
         return;
     }
 
-    PushDouble( IterateParametersIfs( ifSUMIFS));
+    sc::ParamIfsResult aRes;
+    IterateParametersIfs(aRes);
+    PushDouble(rtl::math::approxAdd(aRes.mfSum, aRes.mfMem));
 }
 
 void ScInterpreter::ScAverageIfs()
@@ -5746,7 +5731,9 @@ void ScInterpreter::ScAverageIfs()
         return;
     }
 
-    PushDouble( IterateParametersIfs( ifAVERAGEIFS));
+    sc::ParamIfsResult aRes;
+    IterateParametersIfs(aRes);
+    PushDouble(div(rtl::math::approxAdd(aRes.mfSum, aRes.mfMem), aRes.mfCount));
 }
 
 void ScInterpreter::ScCountIfs()
@@ -5759,7 +5746,9 @@ void ScInterpreter::ScCountIfs()
         return;
     }
 
-    PushDouble( IterateParametersIfs( ifCOUNTIFS));
+    sc::ParamIfsResult aRes;
+    IterateParametersIfs(aRes);
+    PushDouble(aRes.mfCount);
 }
 
 void ScInterpreter::ScMinIfs_MS()
@@ -5772,7 +5761,9 @@ void ScInterpreter::ScMinIfs_MS()
         return;
     }
 
-    PushDouble( IterateParametersIfs( ifMINIFS ) );
+    sc::ParamIfsResult aRes;
+    IterateParametersIfs(aRes);
+    PushDouble((aRes.mfMin < std::numeric_limits<double>::max()) ? aRes.mfMin : 0.0);
 }
 
 
@@ -5786,7 +5777,9 @@ void ScInterpreter::ScMaxIfs_MS()
         return;
     }
 
-    PushDouble( IterateParametersIfs( ifMAXIFS ) );
+    sc::ParamIfsResult aRes;
+    IterateParametersIfs(aRes);
+    PushDouble((aRes.mfMax > std::numeric_limits<double>::min()) ? aRes.mfMax : 0.0);
 }
 
 void ScInterpreter::ScLookup()


More information about the Libreoffice-commits mailing list