diff options
author | Eike Rathke <erack@redhat.com> | 2015-05-05 17:12:45 +0200 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-05-05 17:17:56 +0200 |
commit | 48d7d093bae06b7883434161882cb9d5f2ce08ae (patch) | |
tree | 2e4aac24b92b83769b78a4dc75dd867158525dc6 | |
parent | 8fca0c44e8f21fa2ee1000665856292d5a1c44e9 (diff) |
rework the twisted ShrinkToUsedDataArea logic
It is unnecessary to check the remaining columns/rows twice if they
really contain data, and that even for every empty row removed.
Also, put loops inside conditions instead of conditions inside loop.
Change-Id: Idbb1a647d99806ebab26a17a83b455cacc157c18
-rw-r--r-- | sc/source/core/data/table1.cxx | 68 |
1 files changed, 34 insertions, 34 deletions
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx index b665e9fa6d22..d93d1f4d7ed3 100644 --- a/sc/source/core/data/table1.cxx +++ b/sc/source/core/data/table1.cxx @@ -927,65 +927,65 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS if (rEndRow > MAXROW) rEndRow = MAXROW, o_bShrunk = true; - bool bChanged; - do + while (rStartCol < rEndCol) { - bChanged = false; + if (aCol[rEndCol].IsEmptyBlock( rStartRow, rEndRow)) + { + --rEndCol; + o_bShrunk = true; + } + else + break; // while + } + if (!bStickyLeftCol) + { while (rStartCol < rEndCol) { - if (aCol[rEndCol].IsEmptyBlock( rStartRow, rEndRow)) + if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow)) { - --rEndCol; - bChanged = true; + ++rStartCol; + o_bShrunk = true; } else break; // while } + } - if (!bStickyLeftCol) - { - while (rStartCol < rEndCol) - { - if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow)) - { - ++rStartCol; - bChanged = true; - } - else - break; // while - } - } - - if (!bColumnsOnly) + if (!bColumnsOnly) + { + if (!bStickyTopRow) { - if (!bStickyTopRow && rStartRow < rEndRow) + while (rStartRow < rEndRow) { bool bFound = false; for (SCCOL i=rStartCol; i<=rEndCol && !bFound; i++) + { if (aCol[i].HasDataAt( rStartRow)) bFound = true; + } if (!bFound) { ++rStartRow; - bChanged = true; + o_bShrunk = true; } + else + break; // while } + } - if (rStartRow < rEndRow) + while (rStartRow < rEndRow) + { + SCROW nLastDataRow = GetLastDataRow( rStartCol, rEndCol, rEndRow); + if (0 <= nLastDataRow && nLastDataRow < rEndRow) { - SCROW nLastDataRow = GetLastDataRow( rStartCol, rEndCol, rEndRow); - if (0 <= nLastDataRow && nLastDataRow < rEndRow) - { - rEndRow = std::max( rStartRow, nLastDataRow); - bChanged = true; - } + rEndRow = std::max( rStartRow, nLastDataRow); + o_bShrunk = true; } + else + break; // while } - - if (bChanged) - o_bShrunk = true; - } while( bChanged ); + } return rStartCol != rEndCol || (bColumnsOnly ? !aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow) : |