diff options
author | Dennis Francis <dennis.francis@collabora.com> | 2018-12-06 00:09:59 +0530 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-12-07 16:25:11 +0100 |
commit | cb52b112c0d44d7a6849f773fd1ee4e863ab91da (patch) | |
tree | eb89154a6b2642618c4643a0b49589061c267b3f /sc/source/core/data/table1.cxx | |
parent | 50cb96346ad54bcdb172acf11b4befe540e2b152 (diff) |
Find actual data area inside the main-range...
and trim all ranges to match this actual data area. Don't do
this optimization for COUNTIFS where there is no main-range.
This optimization is also turned off if any of the parameter
ranges are not double-refs.
Benefits in cases like -
=SUMIFS(A:A, B:B, ">=20", C:C, "<=10") and the is data only
in say A1:A10000 and rest are empty. Range trimming in this
case saves lot of execution time and memory (for vConditions
and vRefArrayConditions).
Change-Id: I6b4ad91e23f89dc48603b98000bcef4dbdb03112
Reviewed-on: https://gerrit.libreoffice.org/64657
Tested-by: Jenkins
Reviewed-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'sc/source/core/data/table1.cxx')
-rw-r--r-- | sc/source/core/data/table1.cxx | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index 6a3527f36709..7e9fd9aa524a 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -904,6 +904,47 @@ void ScTable::GetDataArea( SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, S } } +bool ScTable::GetDataAreaSubrange( ScRange& rRange ) const +{ + SCCOL nCol1 = rRange.aStart.Col(), nCol2 = rRange.aEnd.Col(); + + if ( nCol1 >= aCol.size() ) + return false; + + nCol2 = std::min<SCCOL>( nCol2, aCol.size()-1 ); + + SCROW nRow1 = rRange.aStart.Row(), nRow2 = rRange.aEnd.Row(); + + SCCOL nFirstNonEmptyCol = -1, nLastNonEmptyCol = -1; + SCROW nRowStart = nRow2, nRowEnd = nRow1; + + for ( SCCOL nCol = nCol1; nCol <= nCol2; ++nCol ) + { + SCROW nRowStartThis = nRow1, nRowEndThis = nRow2; + bool bTrimmed = aCol[nCol].TrimEmptyBlocks(nRowStartThis, nRowEndThis); + if ( bTrimmed ) + { + if ( nFirstNonEmptyCol == -1 ) + nFirstNonEmptyCol = nCol; + nLastNonEmptyCol = nCol; + + nRowStart = std::min<SCROW>(nRowStart, nRowStartThis); + nRowEnd = std::max<SCROW>(nRowEnd, nRowEndThis); + } + } + + if ( nFirstNonEmptyCol == -1 ) + return false; + + assert(nFirstNonEmptyCol <= nLastNonEmptyCol); + assert(nRowStart <= nRowEnd); + + rRange.aStart.Set(nFirstNonEmptyCol, nRowStart, rRange.aStart.Tab()); + rRange.aEnd.Set(nLastNonEmptyCol, nRowEnd, rRange.aEnd.Tab()); + + return true; +} + bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rStartRow, SCCOL& rEndCol, SCROW& rEndRow, bool bColumnsOnly, bool bStickyTopRow, bool bStickyLeftCol, bool bConsiderCellNotes, bool bConsiderCellDrawObjects ) const |