[Libreoffice-commits] core.git: 2 commits - i18npool/source

Michael Stahl mstahl at redhat.com
Mon Mar 9 16:23:04 PDT 2015


 i18npool/source/search/textsearch.cxx |   42 ++++++++++++++--------------------
 1 file changed, 18 insertions(+), 24 deletions(-)

New commits:
commit 666fb8b7bc210be6d785515bc7660e5a5d19b82e
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

diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 40dffc9..8dda89d 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));
             }
         }
commit 806ced87cfe3da72df0d8e4faf5b82535fc7d1b7
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

diff --git a/i18npool/source/search/textsearch.cxx b/i18npool/source/search/textsearch.cxx
index 1096599..40dffc9 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