diff options
author | Caolán McNamara <caolanm@redhat.com> | 2019-01-30 17:23:20 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-01-31 09:52:39 +0100 |
commit | 07ec9edc26f675646f04721acb3f1f0334a34530 (patch) | |
tree | f2de11820bd7013cc38d5325598ec869327f3b82 /vcl/source/control | |
parent | 50547d359ff5229da1108b097612412bb06a3000 (diff) |
Related: tdf#122780 skip GetTextWidth() when we don't need the result
Change-Id: I1919d3da162e05ea6fec6269a53344b0625338e9
Reviewed-on: https://gerrit.libreoffice.org/67174
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
Diffstat (limited to 'vcl/source/control')
-rw-r--r-- | vcl/source/control/edit.cxx | 13 |
1 files changed, 9 insertions, 4 deletions
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; } } |