[Libreoffice-commits] core.git: Branch 'libreoffice-4-4' - i18npool/source

Michael Stahl mstahl at redhat.com
Tue Mar 10 12:09:53 PDT 2015


 i18npool/source/search/textsearch.cxx |   21 +++++++++------------
 1 file changed, 9 insertions(+), 12 deletions(-)

New commits:
commit 4bae2ea3b57cb88b34bf8a9eade7ab0a950e0185
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Mar 9 21:32:43 2015 +0100

    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 at redhat.com>
    Tested-by: Eike Rathke <erack at redhat.com>

diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 98aa1b6..7245e9a 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;
             }
         }


More information about the Libreoffice-commits mailing list