diff options
author | Winfried Donkers <winfrieddonkers@libreoffice.org> | 2017-11-29 17:43:14 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2017-11-30 16:30:34 +0100 |
commit | c5d0cffbf42f41349a8575ba52456d9cb07e91c7 (patch) | |
tree | c5a8f278ea7c544713fbbf437223f9229cb5c5e7 | |
parent | 4ec1ba2ac535f078aacfc67a28229fb4159623d3 (diff) |
tdf#97198 follow up: improve efficiency for Calc function RIGHT.
Change-Id: Ie2d5011f9ff73bd42a6f3ced1f709fab65d23c18
Reviewed-on: https://gerrit.libreoffice.org/45517
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
-rw-r--r-- | sc/source/core/tool/interpr1.cxx | 18 |
1 files changed, 5 insertions, 13 deletions
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx index 164c1185e1b8..d3b5829a5db8 100644 --- a/sc/source/core/tool/interpr1.cxx +++ b/sc/source/core/tool/interpr1.cxx @@ -8901,23 +8901,15 @@ void ScInterpreter::ScRight() n = 1; OUString aStr = GetString().getString(); sal_Int32 nLen = aStr.getLength(); - sal_Int32 nIdx = 0; - sal_Int32 nCnt = 0; - while ( nIdx < nLen ) - { - aStr.iterateCodePoints( &nIdx ); - ++nCnt; - } - if ( nCnt <= n ) + if ( nLen <= n ) PushString( aStr ); else { - sal_Int32 nCLen = nCnt; - nIdx = 0; - nCnt = 0; - while ( nIdx < nLen && n < ( nCLen - nCnt ) ) + sal_Int32 nIdx = nLen; + sal_Int32 nCnt = 0; + while ( nIdx > 0 && n > nCnt ) { - aStr.iterateCodePoints( &nIdx ); + aStr.iterateCodePoints( &nIdx, -1 ); ++nCnt; } aStr = aStr.copy( nIdx, nLen - nIdx ); |