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

Eike Rathke erack at redhat.com
Wed Jun 21 21:45:13 UTC 2017


 sc/source/core/tool/scmatrix.cxx |   13 +++++++++----
 1 file changed, 9 insertions(+), 4 deletions(-)

New commits:
commit d3b77628efc72d857c63c8fb91d7ed2b499ac860
Author: Eike Rathke <erack at redhat.com>
Date:   Wed Jun 21 23:42:25 2017 +0200

    Resolves: tdf#108292 WalkAndMatchElements: really limit the match
    
    ... to the columns queried, not just when entering an mdds node. Otherwise it
    would return an unexpected index, plus bailing out early spares unnecessary
    comparisons for the rest of a node block.
    
    Regression of
    
        commit 3fed166279377f7ad702b8911899243b8adff3bf
        Date:   Fri Aug 16 16:29:38 2013 +0200
    
    that started to use
    
        commit 7334f8db6f6004d48e2dbf014f27878a7ae21eb1
        Date:   Fri Aug 16 16:29:27 2013 +0200
    
    with its bad implementation.
    
    Just that VLOOKUP on a matrix with a larger block of same typed data as the
    query *and* a match in an excess column seems to be rare..
    
    Change-Id: Ia4ef3fd56490de82910d5aa13a84be2de851f9b0

diff --git a/sc/source/core/tool/scmatrix.cxx b/sc/source/core/tool/scmatrix.cxx
index 675c05c8881e..812c956bae05 100644
--- a/sc/source/core/tool/scmatrix.cxx
+++ b/sc/source/core/tool/scmatrix.cxx
@@ -1284,6 +1284,8 @@ public:
 
     size_t getMatching() const { return mnResult; }
 
+    size_t getRemainingCount() const { return ((mnCol2 + 1) * maSize.row) - mnIndex; }
+
     size_t compare(const MatrixImplType::element_block_node_type& node) const;
 
     void operator() (const MatrixImplType::element_block_node_type& node)
@@ -1293,7 +1295,7 @@ public:
             return;
 
         // limit lookup to the requested columns
-        if ((mnCol1 * maSize.row) <= mnIndex && mnIndex < ((mnCol2 + 1) * maSize.row))
+        if ((mnCol1 * maSize.row) <= mnIndex && getRemainingCount() > 0)
         {
             mnResult = compare(node);
         }
@@ -1314,7 +1316,8 @@ size_t WalkAndMatchElements<double>::compare(const MatrixImplType::element_block
 
             block_type::const_iterator it = block_type::begin(*node.data);
             block_type::const_iterator itEnd = block_type::end(*node.data);
-            for (; it != itEnd; ++it, nCount++)
+            const size_t nRemaining = getRemainingCount();
+            for (; it != itEnd && nCount < nRemaining; ++it, ++nCount)
             {
                 if (*it == maMatchValue)
                 {
@@ -1329,7 +1332,8 @@ size_t WalkAndMatchElements<double>::compare(const MatrixImplType::element_block
 
             block_type::const_iterator it = block_type::begin(*node.data);
             block_type::const_iterator itEnd = block_type::end(*node.data);
-            for (; it != itEnd; ++it, ++nCount)
+            const size_t nRemaining = getRemainingCount();
+            for (; it != itEnd && nCount < nRemaining; ++it, ++nCount)
             {
                 if (int(*it) == maMatchValue)
                 {
@@ -1359,7 +1363,8 @@ size_t WalkAndMatchElements<svl::SharedString>::compare(const MatrixImplType::el
 
             block_type::const_iterator it = block_type::begin(*node.data);
             block_type::const_iterator itEnd = block_type::end(*node.data);
-            for (; it != itEnd; ++it, ++nCount)
+            const size_t nRemaining = getRemainingCount();
+            for (; it != itEnd && nCount < nRemaining; ++it, ++nCount)
             {
                 if (it->getDataIgnoreCase() == maMatchValue.getDataIgnoreCase())
                 {


More information about the Libreoffice-commits mailing list