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

Matthew J. Francis mjay.francis at gmail.com
Wed Sep 10 07:10:48 PDT 2014


 i18npool/inc/xdictionary.hxx                            |    2 +
 i18npool/source/breakiterator/breakiterator_unicode.cxx |    2 -
 i18npool/source/breakiterator/xdictionary.cxx           |   19 ++++++++++++++++
 3 files changed, 22 insertions(+), 1 deletion(-)

New commits:
commit a34a8fca21c670c4e7ee147d05ed9e6e4136cbe1
Author: Matthew J. Francis <mjay.francis at gmail.com>
Date:   Wed Sep 10 17:34:01 2014 +0800

    fdo#81272 Speed up break iterators
    
    Change-Id: Idcd7de83ff7e551b350db0bf80e2ac78baa67686
    Reviewed-on: https://gerrit.libreoffice.org/11374
    Reviewed-by: Caolán McNamara <caolanm at redhat.com>
    Tested-by: Caolán McNamara <caolanm at redhat.com>

diff --git a/i18npool/inc/xdictionary.hxx b/i18npool/inc/xdictionary.hxx
index 57f5238..f7c0110 100644
--- a/i18npool/inc/xdictionary.hxx
+++ b/i18npool/inc/xdictionary.hxx
@@ -76,6 +76,8 @@ public:
 
 private:
     WordBreakCache cache[CACHE_MAX];
+    OUString segmentCachedString;
+    Boundary segmentCachedBoundary;
 
     bool        seekSegment(const OUString& rText, sal_Int32 pos, Boundary& boundary);
     WordBreakCache& getCache(const sal_Unicode *text, Boundary& boundary);
diff --git a/i18npool/source/breakiterator/breakiterator_unicode.cxx b/i18npool/source/breakiterator/breakiterator_unicode.cxx
index 5270b1d..658d4ff 100644
--- a/i18npool/source/breakiterator/breakiterator_unicode.cxx
+++ b/i18npool/source/breakiterator/breakiterator_unicode.cxx
@@ -185,7 +185,7 @@ void SAL_CALL BreakIterator_Unicode::loadICUBreakIterator(const com::sun::star::
         }
     }
 
-    if (newBreak || !icuBI->aICUText.equals(rText))
+    if (newBreak || icuBI->aICUText.pData != rText.pData)
     {
         // UChar != sal_Unicode in MinGW
         const UChar *pText = reinterpret_cast<const UChar *>(rText.getStr());
diff --git a/i18npool/source/breakiterator/xdictionary.cxx b/i18npool/source/breakiterator/xdictionary.cxx
index 1067e33..95e1cc9 100644
--- a/i18npool/source/breakiterator/xdictionary.cxx
+++ b/i18npool/source/breakiterator/xdictionary.cxx
@@ -271,6 +271,21 @@ bool xdictionary::seekSegment(const OUString &rText, sal_Int32 pos,
     Boundary& segBoundary)
 {
     sal_Int32 indexUtf16;
+
+    if (segmentCachedString.pData != rText.pData) {
+        // Cache the passed text so we can avoid regenerating the segment if it's the same
+        // (pData is refcounted and assigning the OUString references it, which ensures that
+        // the object is the same if we get the same pointer back later)
+        segmentCachedString = rText;
+    } else {
+        // If pos is within the cached boundary, use that boundary
+        if (pos >= segmentCachedBoundary.startPos && pos <= segmentCachedBoundary.endPos) {
+            indexUtf16 = segmentCachedBoundary.startPos;
+            rText.iterateCodePoints(&indexUtf16, 1);
+            return segmentCachedBoundary.endPos > indexUtf16;
+        }
+    }
+
     segBoundary.endPos = segBoundary.startPos = pos;
 
     indexUtf16 = pos;
@@ -293,6 +308,10 @@ bool xdictionary::seekSegment(const OUString &rText, sal_Int32 pos,
             break;
     }
 
+    // Cache the calculated boundary
+    segmentCachedBoundary.startPos = segBoundary.startPos;
+    segmentCachedBoundary.endPos = segBoundary.endPos;
+
     indexUtf16 = segBoundary.startPos;
     rText.iterateCodePoints(&indexUtf16, 1);
     return segBoundary.endPos > indexUtf16;


More information about the Libreoffice-commits mailing list