From 09e9274fc080b471393b806617eb03124db67590 Mon Sep 17 00:00:00 2001 From: Justin Luth Date: Wed, 8 Feb 2017 19:08:07 +0300 Subject: 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. Change-Id: Ib02520a1bf0f77b5ca0ec5ad3165ff7ea879515f Reviewed-on: https://gerrit.libreoffice.org/34038 Tested-by: Jenkins Reviewed-by: Bartosz Kosiorek --- sc/source/filter/excel/xetable.cxx | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sc/source/filter/excel/xetable.cxx b/sc/source/filter/excel/xetable.cxx index a8627c0571e6..0c573e973f1e 100644 --- a/sc/source/filter/excel/xetable.cxx +++ b/sc/source/filter/excel/xetable.cxx @@ -2375,18 +2375,31 @@ 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). - bool bHidden = rDoc.RowHidden(nFrom, nScTab); + 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. @@ -2403,11 +2416,11 @@ XclExpRow& XclExpRowBuffer::GetOrCreateRow( sal_uInt32 nXclRow, bool bRowAlwaysE RowRef p(new XclExpRow(GetRoot(), nFrom, maOutlineBfr, bRowAlwaysEmpty, bHidden, nHeight)); maRowMap.insert(RowMap::value_type(nFrom, p)); } + ++nFrom; } } itr = maRowMap.find(nXclRow); return *itr->second; - } // Cell Table -- cgit v1.2.3