[Libreoffice-commits] core.git: Branch 'libreoffice-5-3' - sc/source

Justin Luth justin_luth at sil.org
Wed Feb 15 16:00:27 UTC 2017


 sc/source/filter/excel/xetable.cxx |   37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

New commits:
commit 854bae75ab891423182f11604aedc42c6bfa334e
Author: Justin Luth <justin_luth at sil.org>
Date:   Wed Feb 8 19:08:07 2017 +0300

    Optimize Excel GetOrCreateRow: reduce loops
    
    for ( size_t nFrom = maRowMap.size(); nFrom <= nXclRow; ++nFrom )
    
    This previous code worked best under the assumption
    that every row is added to the map. However, the size of the
    map actually has no correlation to the row numbers contained in it
    when many rows are identical to each other (think silly formatting
    and empty rows - related to tdf#105840)
    Thus row 1,000,000 could occupy slot 2, and every access of that row
    would then trigger nearly 1 million redundant loops.
    
    Optimize:
    -check to see if the row already exists - if so do nothing.
    -existance of higher rows indicates there are no missing rows.
    -build missing rows from the previously-mapped row.
    
    Reviewed-on: https://gerrit.libreoffice.org/34038
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>
    
    Conflicts:
    
    	sc/source/filter/excel/xetable.cxx
    
    Change-Id: Ib02520a1bf0f77b5ca0ec5ad3165ff7ea879515f
    Reviewed-on: https://gerrit.libreoffice.org/34275
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Bartosz Kosiorek <gang65 at poczta.onet.pl>

diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx
index fe39f238..9f8eec1 100644
--- a/sc/source/filter/excel/xetable.cxx
+++ b/sc/source/filter/excel/xetable.cxx
@@ -2374,22 +2374,39 @@ void XclExpRowBuffer::SaveXml( XclExpXmlStream& rStrm )
 
 XclExpRow& XclExpRowBuffer::GetOrCreateRow( sal_uInt32 nXclRow, bool bRowAlwaysEmpty )
 {
-    RowMap::iterator itr = maRowMap.begin();
-    ScDocument& rDoc = GetRoot().GetDoc();
-    SCTAB nScTab = GetRoot().GetCurrScTab();
-    for ( size_t nFrom = maRowMap.size(); nFrom <= nXclRow; ++nFrom )
+    RowMap::iterator itr = maRowMap.lower_bound( nXclRow );
+    const bool bFound = itr != maRowMap.end();
+    // bFoundHigher: nXclRow was identical to the previous entry, so not explicitly created earlier
+    const bool bFoundHigher = bFound && itr != maRowMap.find( nXclRow );
+    if( !bFound || bFoundHigher )
     {
-        itr = maRowMap.find(nFrom);
-        if ( itr == maRowMap.end() )
+        size_t nFrom = 0;
+        if( itr != maRowMap.begin() )
+        {
+            --itr;
+            if( bFoundHigher )
+                nFrom = nXclRow;
+            else
+                nFrom = itr->first + 1;
+        }
+
+        const ScDocument& rDoc = GetRoot().GetDoc();
+        const SCTAB nScTab = GetRoot().GetCurrScTab();
+        // create the missing rows first
+        while( nFrom <= nXclRow )
         {
             // only create RowMap entries if it is first row in spreadsheet,
             // if it is the desired row, for rows that height differ from previous,
             // if row is collapsed, has outline level (tdf#100347), or row is hidden (tdf#98106).
-            if ( !nFrom || ( nFrom == nXclRow ) ||
-                 ( rDoc.GetRowHeight(nFrom, nScTab, false) != rDoc.GetRowHeight(nFrom - 1, nScTab, false) ) ||
+            const bool bHidden = rDoc.RowHidden(nFrom, nScTab);
+            // Always get the actual row height even if the manual size flag is
+            // not set, to correctly export the heights of rows with wrapped
+            // texts.
+            const sal_uInt16 nHeight = rDoc.GetRowHeight(nFrom, nScTab, false);
+            if ( !nFrom || ( nFrom == nXclRow ) || bHidden ||
                  ( maOutlineBfr.IsCollapsed() ) ||
                  ( maOutlineBfr.GetLevel() != 0 ) ||
-                 ( rDoc.RowHidden(nFrom, nScTab) ) )
+                 ( nHeight != rDoc.GetRowHeight(nFrom - 1, nScTab, false) ) )
             {
                 if( maOutlineBfr.GetLevel() > mnHighestOutlineLevel )
                 {
@@ -2398,11 +2415,11 @@ XclExpRow& XclExpRowBuffer::GetOrCreateRow( sal_uInt32 nXclRow, bool bRowAlwaysE
                 RowRef p(new XclExpRow(GetRoot(), nFrom, maOutlineBfr, bRowAlwaysEmpty));
                 maRowMap.insert(RowMap::value_type(nFrom, p));
             }
+            ++nFrom;
         }
     }
     itr = maRowMap.find(nXclRow);
     return *itr->second;
-
 }
 
 // Cell Table


More information about the Libreoffice-commits mailing list