sc/source/core/tool/scmatrix.cxx |   10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

New commits:
commit 93a779e56cc9cb02c0e053d7a58589ed9fd10636
Author:     Noel Grandin <noelgran...@gmail.com>
AuthorDate: Fri Apr 18 19:49:30 2025 +0200
Commit:     Noel Grandin <noelgran...@gmail.com>
CommitDate: Sat Apr 19 13:00:47 2025 +0200

    speed up EvalMatrix
    
    by (a) using the iterator instead of doing an index lookup for each 
iteration and (b) switching the loop so we work with the natural data layout
    
    Change-Id: I35bca868f72657c279c33e221deafd672272c8aa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/184358
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index a8f27380d9aa..337281f520e9 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1136,11 +1136,12 @@ double EvalMatrix(const MatrixImplType& rMat)
 {
     Evaluator aEval;
     size_t nRows = rMat.size().row, nCols = rMat.size().column;
-    for (size_t i = 0; i < nRows; ++i)
+
+    MatrixImplType::const_position_type aPos = rMat.position(0, 0);
+    for (size_t nC = 0; nC < nCols; ++nC)
     {
-        for (size_t j = 0; j < nCols; ++j)
+        for (size_t nR = 0; nR < nRows; ++nR)
         {
-            MatrixImplType::const_position_type aPos = rMat.position(i, j);
             mdds::mtm::element_t eType = rMat.get_type(aPos);
             if (eType != mdds::mtm::element_numeric && eType != 
mdds::mtm::element_boolean)
                 // assuming a CompareMat this is an error
@@ -1152,8 +1153,11 @@ double EvalMatrix(const MatrixImplType& rMat)
                 return fVal;
 
             aEval.operate(fVal);
+
+            aPos = MatrixImplType::next_position(aPos);
         }
     }
+
     return aEval.result();
 }
 

Reply via email to