From f91a411340ae204ce1e6997f22e0352a4c6a8355 Mon Sep 17 00:00:00 2001 From: Noel Grandin Date: Thu, 23 May 2024 15:09:52 +0200 Subject: reduce cost of calc column height calculation avoid calling GetTextWidth unless we really need to Change-Id: Ibb0f378e632fa3fce68b4819028630759baf4eb5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167988 Tested-by: Jenkins Reviewed-by: Michael Meeks --- sc/source/core/data/column2.cxx | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'sc/source') diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx index c4ac17ffe358..e62ac56a1e14 100644 --- a/sc/source/core/data/column2.cxx +++ b/sc/source/core/data/column2.cxx @@ -307,9 +307,10 @@ tools::Long ScColumn::GetNeededSize( { // SetFont is moved up - Size aSize( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); + Size aSize; if ( eOrient != SvxCellOrientation::Standard ) { + aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); tools::Long nTemp = aSize.Width(); aSize.setWidth( aSize.Height() ); aSize.setHeight( nTemp ); @@ -318,6 +319,7 @@ tools::Long ScColumn::GetNeededSize( { //TODO: take different X/Y scaling into consideration + aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); double nRealOrient = toRadians(nRotate); double nCosAbs = fabs( cos( nRealOrient ) ); double nSinAbs = fabs( sin( nRealOrient ) ); @@ -347,8 +349,13 @@ tools::Long ScColumn::GetNeededSize( } aSize = Size( nWidth, nHeight ); + nValue = bWidth ? aSize.Width() : aSize.Height(); } - nValue = bWidth ? aSize.Width() : aSize.Height(); + else if (bBreak && !bWidth) + aSize = Size( pDev->GetTextWidth( aValStr ), pDev->GetTextHeight() ); + else + // in the common case (height), avoid calling the expensive GetTextWidth + nValue = bWidth ? pDev->GetTextWidth( aValStr ) : pDev->GetTextHeight(); if ( bAddMargin ) { -- cgit v1.2.3