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

Michael Stahl mstahl at redhat.com
Tue Mar 10 12:11:15 PDT 2015


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

New commits:
commit cfaeddd9ed07fad75182eb0cd040e63d08502b5e
Author: Michael Stahl <mstahl at redhat.com>
Date:   Mon Mar 9 23:56:24 2015 +0100

    tdf#89665: i18npool: speed up TextSearch::searchBackward()
    
    There does not appear to be a good reason why searchBackward()
    needs to call transliterate() on the entire passed string, so don't do that,
    as in the previous commit for the other direction.
    
    Change-Id: Iadfca806da89bf8825e5a3df7fcad64ea08d7f9c
    (cherry picked from commit 666fb8b7bc210be6d785515bc7660e5a5d19b82e)
    Reviewed-on: https://gerrit.libreoffice.org/14827
    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 7245e9a..959227df 100644
--- a/i18npool/source/search/textsearch.cxx
+++ b/i18npool/source/search/textsearch.cxx
@@ -328,25 +328,22 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
     SearchResult sres;
 
     OUString in_str(searchStr);
-    sal_Int32 newStartPos = startPos;
-    sal_Int32 newEndPos = endPos;
 
     bUsePrimarySrchStr = true;
 
     if ( xTranslit.is() )
     {
         // apply only simple 1<->1 transliteration here
-        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(startPos - endPos);
+    in_str = xTranslit->transliterate( searchStr, endPos, startPos - endPos, offset );
 
         // JP 20.6.2001: also the start and end positions must be corrected!
-        if( startPos < searchStr.getLength() )
-            newStartPos = FindPosInSeq_Impl( offset, startPos );
-        else
-            newStartPos = in_str.getLength();
+        sal_Int32 const newStartPos = (startPos < searchStr.getLength())
+            ? FindPosInSeq_Impl( offset, startPos )
+            : in_str.getLength();
 
-        if( endPos )
-            newEndPos = FindPosInSeq_Impl( offset, endPos );
+        sal_Int32 const newEndPos =
+            (endPos == 0) ? 0 : FindPosInSeq_Impl( offset, endPos );
 
         sres = (this->*fnBackward)( in_str, newStartPos, newEndPos );
 
@@ -360,14 +357,14 @@ SearchResult TextSearch::searchBackward( const OUString& searchStr, sal_Int32 st
             for ( sal_Int32 k = 0; k < nGroups; k++ )
             {
                 const sal_Int32 nStart = sres.startOffset[k];
-                if (nStart > 0)
+                if (endPos > 0 || nStart > 0)
                     sres.startOffset[k] = offset[(nStart <= nOffsets ? nStart : 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 (endPos > 0 || nStop > 0)
                     sres.endOffset[k] = (nStop < nOffsets ? offset[nStop] : (offset[nOffsets - 1] + 1));
             }
         }


More information about the Libreoffice-commits mailing list