diff options
author | Michael Stahl <mstahl@redhat.com> | 2015-03-09 21:32:43 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2015-03-10 19:09:29 +0000 |
commit | 4bae2ea3b57cb88b34bf8a9eade7ab0a950e0185 (patch) | |
tree | f81c521c8043683ad56c8835cc4dd6f3fdc14f67 /i18npool | |
parent | 9e7fb91d272757b0e3ddabeb72eedc83e9d89b5e (diff) |
tdf#89665: i18npool: speed up TextSearch::searchForward()
There does not appear to be a good reason why searchForward() needs to
call transliterate() on the entire passed string.
Restricting it to the passed range speeds it up from 104 billion to 0.19
billion callgrind cycles when built with GCC 4.9.2 -m32 -Os.
Change-Id: I440f16c34f38659b64f1eb60c50f0e414e3dfee8
(cherry picked from commit 806ced87cfe3da72df0d8e4faf5b82535fc7d1b7)
Reviewed-on: https://gerrit.libreoffice.org/14826
Reviewed-by: Eike Rathke <erack@redhat.com>
Tested-by: Eike Rathke <erack@redhat.com>
Diffstat (limited to 'i18npool')
-rw-r--r-- | i18npool/source/search/textsearch.cxx | 21 |
1 files changed, 9 insertions, 12 deletions
diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx index 98aa1b6cc3f2..7245e9a6a4ab 100644 --- a/i18npool/source/search/textsearch.cxx +++ b/i18npool/source/search/textsearch.cxx @@ -232,25 +232,22 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta SearchResult sres; OUString in_str(searchStr); - sal_Int32 newStartPos = startPos; - sal_Int32 newEndPos = endPos; bUsePrimarySrchStr = true; if ( xTranslit.is() ) { // apply normal transliteration (1<->1, 1<->0) - com::sun::star::uno::Sequence <sal_Int32> offset( in_str.getLength()); - in_str = xTranslit->transliterate( searchStr, 0, in_str.getLength(), offset ); + com::sun::star::uno::Sequence<sal_Int32> offset(endPos - startPos); + in_str = xTranslit->transliterate( searchStr, startPos, endPos - startPos, offset ); // JP 20.6.2001: also the start and end positions must be corrected! - if( startPos ) - newStartPos = FindPosInSeq_Impl( offset, startPos ); + sal_Int32 const newStartPos = + (startPos == 0) ? 0 : FindPosInSeq_Impl( offset, startPos ); - if( endPos < searchStr.getLength() ) - newEndPos = FindPosInSeq_Impl( offset, endPos ); - else - newEndPos = in_str.getLength(); + sal_Int32 const newEndPos = (endPos < searchStr.getLength()) + ? FindPosInSeq_Impl( offset, endPos ) + : in_str.getLength(); sres = (this->*fnForward)( in_str, newStartPos, newEndPos ); @@ -264,14 +261,14 @@ SearchResult TextSearch::searchForward( const OUString& searchStr, sal_Int32 sta for ( sal_Int32 k = 0; k < nGroups; k++ ) { const sal_Int32 nStart = sres.startOffset[k]; - if (nStart > 0) + if (startPos > 0 || nStart > 0) sres.startOffset[k] = (nStart < nOffsets ? offset[nStart] : (offset[nOffsets - 1] + 1)); // JP 20.6.2001: end is ever exclusive and then don't return // the position of the next character - return the // next position behind the last found character! // "a b c" find "b" must return 2,3 and not 2,4!!! const sal_Int32 nStop = sres.endOffset[k]; - if (nStop > 0) + if (startPos > 0 || nStop > 0) sres.endOffset[k] = offset[(nStop <= nOffsets ? nStop : nOffsets) - 1] + 1; } } |