reduce iteration in ScViewData::GetScrPos

we already have a ScTable::GetRowHeightScaled method that uses spans, so use
that.

Change-Id: I126292b4a8b37ebf2d4f737dcbfdadc31226531e
Reviewed-on: https://gerrit.libreoffice.org/82520
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
This commit is contained in:
Noel Grandin 2019-11-12 16:00:55 +02:00
parent 8c85782bbe
commit feec8e3c34
5 changed files with 39 additions and 26 deletions

View File

@ -1858,7 +1858,7 @@ public:
* specified height.
*/
SCROW GetRowForHeight( SCTAB nTab, sal_uLong nHeight ) const;
sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, double fScale ) const;
sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, SCTAB nTab, double fScale, const sal_uLong* pnMaxHeight = nullptr ) const;
SC_DLLPUBLIC sal_uLong GetColOffset( SCCOL nCol, SCTAB nTab, bool bHiddenAsZero = true ) const;
SC_DLLPUBLIC sal_uLong GetRowOffset( SCROW nRow, SCTAB nTab, bool bHiddenAsZero = true ) const;

View File

@ -805,7 +805,7 @@ public:
sal_uLong GetColWidth( SCCOL nStartCol, SCCOL nEndCol ) const;
sal_uInt16 GetRowHeight( SCROW nRow, SCROW* pStartRow, SCROW* pEndRow, bool bHiddenAsZero = true ) const;
sal_uLong GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZero = true ) const;
sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale ) const;
sal_uLong GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong* pnMaxHeight = nullptr ) const;
sal_uLong GetColOffset( SCCOL nCol, bool bHiddenAsZero = true ) const;
sal_uLong GetRowOffset( SCROW nRow, bool bHiddenAsZero = true ) const;

View File

@ -4183,7 +4183,7 @@ SCROW ScDocument::GetRowForHeight( SCTAB nTab, sal_uLong nHeight ) const
}
sal_uLong ScDocument::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow,
SCTAB nTab, double fScale ) const
SCTAB nTab, double fScale, const sal_uLong* pnMaxHeight ) const
{
// faster for a single row
if (nStartRow == nEndRow)
@ -4194,7 +4194,7 @@ sal_uLong ScDocument::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow,
return 0;
if ( ValidTab(nTab) && nTab < static_cast<SCTAB>(maTabs.size()) && maTabs[nTab] )
return maTabs[nTab]->GetScaledRowHeight( nStartRow, nEndRow, fScale);
return maTabs[nTab]->GetScaledRowHeight( nStartRow, nEndRow, fScale, pnMaxHeight );
OSL_FAIL("wrong sheet number");
return 0;

View File

@ -3243,7 +3243,7 @@ sal_uLong ScTable::GetRowHeight( SCROW nStartRow, SCROW nEndRow, bool bHiddenAsZ
return (nEndRow - nStartRow + 1) * static_cast<sal_uLong>(ScGlobal::nStdRowHeight);
}
sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale ) const
sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fScale, const sal_uLong* pnMaxHeight ) const
{
OSL_ENSURE(ValidRow(nStartRow) && ValidRow(nEndRow),"wrong row number");
@ -3269,8 +3269,18 @@ sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fS
SCROW nSegmentEnd = std::min( nLastRow, aData.mnRow2 );
// round-down a single height value, multiply resulting (pixel) values
sal_uLong nOneHeight = static_cast<sal_uLong>( aData.mnValue * fScale );
nHeight += nOneHeight * ( nSegmentEnd + 1 - nRow );
const sal_uLong nOneHeight = static_cast<sal_uLong>( aData.mnValue * fScale );
SCROW nRowsInSegment = nSegmentEnd + 1 - nRow;
if (pnMaxHeight)
{
nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
nHeight += nOneHeight * nRowsInSegment;
if (nHeight > *pnMaxHeight)
return nHeight;
}
else
nHeight += nOneHeight * nRowsInSegment;
nRow = nSegmentEnd + 1;
}
@ -3280,7 +3290,17 @@ sal_uLong ScTable::GetScaledRowHeight( SCROW nStartRow, SCROW nEndRow, double fS
return nHeight;
}
else
return static_cast<sal_uLong>((nEndRow - nStartRow + 1) * ScGlobal::nStdRowHeight * fScale);
{
const sal_uLong nOneHeight = static_cast<sal_uLong>(ScGlobal::nStdRowHeight * fScale);
SCROW nRowsInSegment = nEndRow - nStartRow + 1;
if (pnMaxHeight)
{
nRowsInSegment = std::min(nRowsInSegment, static_cast<SCROW>(*pnMaxHeight / nOneHeight + 1));
return nOneHeight * nRowsInSegment;
}
else
return static_cast<sal_uLong>(nRowsInSegment * nOneHeight);
}
}
sal_uInt16 ScTable::GetOriginalHeight( SCROW nRow ) const // non-0 even if hidden

View File

@ -2100,7 +2100,7 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
const_cast<ScViewData*>(this)->aScrSize.setHeight( pView->GetGridHeight(eWhichY) );
}
sal_uInt16 nTSize;
sal_uLong nTSize;
bool bIsTiledRendering = comphelper::LibreOfficeKit::isActive();
@ -2168,27 +2168,20 @@ Point ScViewData::GetScrPos( SCCOL nWhereX, SCROW nWhereY, ScSplitPos eWhich,
if (nWhereY >= nStartPosY)
{
for (SCROW nY = nStartPosY; nY < nWhereY && (bAllowNeg || bIsTiledRendering || nScrPosY <= aScrSize.Height()); nY++)
if (bAllowNeg || bIsTiledRendering || nScrPosY <= aScrSize.Height())
{
if ( nY > pDoc->MaxRow() )
if ( nWhereY-1 > pDoc->MaxRow() )
nScrPosY = 0x7FFFFFFF;
else if (bAllowNeg || bIsTiledRendering)
{
sal_uLong nSizeYPix = pDoc->GetScaledRowHeight( nStartPosY, nWhereY-1, nTabNo, nPPTY );
nScrPosY += nSizeYPix;
}
else
{
nTSize = pDoc->GetRowHeight( nY, nTabNo );
if (nTSize)
{
long nSizeYPix = ToPixel( nTSize, nPPTY );
nScrPosY += nSizeYPix;
}
else if ( nY < pDoc->MaxRow() )
{
// skip multiple hidden rows (forward only for now)
SCROW nNext = pDoc->FirstVisibleRow(nY + 1, pDoc->MaxRow(), nTabNo);
if ( nNext > pDoc->MaxRow() )
nY = pDoc->MaxRow();
else
nY = nNext - 1; // +=nDir advances to next visible row
}
sal_uLong nMaxHeight = aScrSize.getHeight() - nScrPosY;
sal_uLong nSizeYPix = pDoc->GetScaledRowHeight( nStartPosY, nWhereY-1, nTabNo, nPPTY, &nMaxHeight );
nScrPosY += nSizeYPix;
}
}
}