sc/inc/document.hxx            |    6 ++++++
 sc/source/core/data/table2.cxx |   35 +++++++++++++++++++++++++++++++----
 2 files changed, 37 insertions(+), 4 deletions(-)

New commits:
commit 0638c640abea8b5b420ede90bb9d14e0560efe53
Author: Kohei Yoshida <kohei.yosh...@collabora.com>
Date:   Fri Oct 7 21:51:04 2016 -0400

    Reduce the number of calls to underlying flat_segment_tree structure.
    
    By replacing the getValue() call to getRangeData().
    
    Change-Id: Ia563b08dd356d9653e6a6ce16256196b28f56b65
    (cherry picked from commit 7345a032bb6758dcbe425c911d557d0b22d7d5ec)
    Reviewed-on: https://gerrit.libreoffice.org/29604
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index e6f09e2..5809930 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -3678,9 +3678,13 @@ sal_uLong ScTable::GetRowOffset( SCROW nRow, bool 
bHiddenAsZero ) const
 
 SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const
 {
-    sal_uInt32 nSum = 0;
+    sal_uLong nSum = 0;
 
     ScFlatBoolRowSegments::RangeData aData;
+
+    ScFlatUInt16RowSegments::RangeData aRowHeightRange;
+    aRowHeightRange.mnRow2 = -1;
+
     for (SCROW nRow = 0; nRow <= MAXROW; ++nRow)
     {
         if (!mpHiddenRows->getRangeData(nRow, aData))
@@ -3694,8 +3698,15 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const
             continue;
         }
 
-        sal_uInt32 nNew = mpRowHeights->getValue(nRow);
-        nSum += nNew;
+        if (aRowHeightRange.mnRow2 < nRow)
+        {
+            if (!mpRowHeights->getRangeData(nRow, aRowHeightRange))
+                // Failed to fetch the range data for whatever reason.
+                break;
+        }
+
+        nSum += aRowHeightRange.mnValue;
+
         if (nSum > nHeight)
         {
             if (nRow >= MAXROW)
commit a7a9bc35edbc3505d4f7b65a78c0b2d92d905a9a
Author: Kohei Yoshida <kohei.yosh...@collabora.com>
Date:   Fri Oct 7 21:34:51 2016 -0400

    Properly skip the hidden row(s) at the end.
    
    This method is supposed to return the first visible row that occurs
    below the specified hight.  The old code would sometimes return a
    hidden row.
    
    Change-Id: Idf32c625c4f51355cd5d8a9f12ae9bbdddd4e5aa
    (cherry picked from commit 61b76cd8ca6a4a98a2ffe6fb42c73eba561aa87f)
    Reviewed-on: https://gerrit.libreoffice.org/29603
    Reviewed-by: Ashod Nakashian <ashnak...@gmail.com>
    Tested-by: Ashod Nakashian <ashnak...@gmail.com>

diff --git a/sc/inc/document.hxx b/sc/inc/document.hxx
index 574f937..70c6b32 100644
--- a/sc/inc/document.hxx
+++ b/sc/inc/document.hxx
@@ -1566,6 +1566,12 @@ public:
     SC_DLLPUBLIC sal_uInt16         GetRowHeight( SCROW nRow, SCTAB nTab, bool 
bHiddenAsZero = true ) const;
     SC_DLLPUBLIC sal_uInt16         GetRowHeight( SCROW nRow, SCTAB nTab, 
SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero = true ) const;
     SC_DLLPUBLIC sal_uLong          GetRowHeight( SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab, bool bHiddenAsZero = true ) const;
+
+    /**
+     * Given the height i.e. total vertical distance from the top of the sheet
+     * grid, return the first visible row whose top position is below the
+     * specified height.
+     */
     SCROW                       GetRowForHeight( SCTAB nTab, sal_uLong nHeight 
) const;
     sal_uLong                       GetScaledRowHeight( SCROW nStartRow, SCROW 
nEndRow, SCTAB nTab, double fScale ) const;
     SC_DLLPUBLIC sal_uLong          GetColOffset( SCCOL nCol, SCTAB nTab, bool 
bHiddenAsZero = true ) const;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index bdddb60..e6f09e2 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -3684,10 +3684,12 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const
     for (SCROW nRow = 0; nRow <= MAXROW; ++nRow)
     {
         if (!mpHiddenRows->getRangeData(nRow, aData))
+            // Failed to fetch the range data for whatever reason.
             break;
 
         if (aData.mbValue)
         {
+            // This row is hidden.  Skip ahead all hidden rows.
             nRow = aData.mnRow2;
             continue;
         }
@@ -3696,7 +3698,21 @@ SCROW ScTable::GetRowForHeight(sal_uLong nHeight) const
         nSum += nNew;
         if (nSum > nHeight)
         {
-            return nRow < MAXROW ? nRow + 1 : MAXROW;
+            if (nRow >= MAXROW)
+                return MAXROW;
+
+            // Find the next visible row.
+            ++nRow;
+
+            if (!mpHiddenRows->getRangeData(nRow, aData))
+                // Failed to fetch the range data for whatever reason.
+                break;
+
+            if (aData.mbValue)
+                // These rows are hidden.
+                nRow = aData.mnRow2 + 1;
+
+            return nRow <= MAXROW ? nRow : MAXROW;
         }
     }
     return -1;
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to