From 07ec9edc26f675646f04721acb3f1f0334a34530 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Wed, 30 Jan 2019 17:23:20 +0000 Subject: Related: tdf#122780 skip GetTextWidth() when we don't need the result MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Change-Id: I1919d3da162e05ea6fec6269a53344b0625338e9 Reviewed-on: https://gerrit.libreoffice.org/67174 Tested-by: Jenkins Reviewed-by: Caolán McNamara Tested-by: Caolán McNamara --- vcl/source/control/edit.cxx | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) (limited to 'vcl') diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx index f15daa864ede..bd5c6c8c55fc 100644 --- a/vcl/source/control/edit.cxx +++ b/vcl/source/control/edit.cxx @@ -1131,14 +1131,19 @@ void Edit::ImplShowCursor( bool bOnlyIfVisible ) void Edit::ImplAlign() { + if (mnAlign == EDIT_ALIGN_LEFT && !mnXOffset) + { + // short circuit common case and avoid slow GetTextWidth() calc + return; + } + long nTextWidth = GetTextWidth( ImplGetText() ); long nOutWidth = GetOutputSizePixel().Width(); if ( mnAlign == EDIT_ALIGN_LEFT ) { - if( mnXOffset && ( nTextWidth < nOutWidth ) ) + if (nTextWidth < nOutWidth) mnXOffset = 0; - } else if ( mnAlign == EDIT_ALIGN_RIGHT ) { @@ -1161,8 +1166,8 @@ void Edit::ImplAlign() } else if( mnAlign == EDIT_ALIGN_CENTER ) { - // would be nicer with check while scrolling but then it's not centred in scrolled state - mnXOffset = (nOutWidth - nTextWidth) / 2; + // would be nicer with check while scrolling but then it's not centred in scrolled state + mnXOffset = (nOutWidth - nTextWidth) / 2; } } -- cgit