Kaydet (Commit) 48d7d093 authored tarafından Eike Rathke's avatar Eike Rathke

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
üst 8fca0c44
...@@ -927,65 +927,65 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS ...@@ -927,65 +927,65 @@ bool ScTable::ShrinkToUsedDataArea( bool& o_bShrunk, SCCOL& rStartCol, SCROW& rS
if (rEndRow > MAXROW) if (rEndRow > MAXROW)
rEndRow = MAXROW, o_bShrunk = true; rEndRow = MAXROW, o_bShrunk = true;
bool bChanged; while (rStartCol < rEndCol)
do
{ {
bChanged = false; if (aCol[rEndCol].IsEmptyBlock( rStartRow, rEndRow))
{
--rEndCol;
o_bShrunk = true;
}
else
break; // while
}
if (!bStickyLeftCol)
{
while (rStartCol < rEndCol) while (rStartCol < rEndCol)
{ {
if (aCol[rEndCol].IsEmptyBlock( rStartRow, rEndRow)) if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow))
{ {
--rEndCol; ++rStartCol;
bChanged = true; o_bShrunk = true;
} }
else else
break; // while break; // while
} }
}
if (!bStickyLeftCol) if (!bColumnsOnly)
{ {
while (rStartCol < rEndCol) if (!bStickyTopRow)
{
if (aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow))
{
++rStartCol;
bChanged = true;
}
else
break; // while
}
}
if (!bColumnsOnly)
{ {
if (!bStickyTopRow && rStartRow < rEndRow) while (rStartRow < rEndRow)
{ {
bool bFound = false; bool bFound = false;
for (SCCOL i=rStartCol; i<=rEndCol && !bFound; i++) for (SCCOL i=rStartCol; i<=rEndCol && !bFound; i++)
{
if (aCol[i].HasDataAt( rStartRow)) if (aCol[i].HasDataAt( rStartRow))
bFound = true; bFound = true;
}
if (!bFound) if (!bFound)
{ {
++rStartRow; ++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); rEndRow = std::max( rStartRow, nLastDataRow);
if (0 <= nLastDataRow && nLastDataRow < rEndRow) o_bShrunk = true;
{
rEndRow = std::max( rStartRow, nLastDataRow);
bChanged = true;
}
} }
else
break; // while
} }
}
if (bChanged)
o_bShrunk = true;
} while( bChanged );
return rStartCol != rEndCol || (bColumnsOnly ? return rStartCol != rEndCol || (bColumnsOnly ?
!aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow) : !aCol[rStartCol].IsEmptyBlock( rStartRow, rEndRow) :
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment