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

Khaled Hosny khaledhosny at eglug.org
Tue May 22 17:29:49 UTC 2018


 i18npool/inc/breakiterator_th.hxx                  |    5 --
 i18npool/source/breakiterator/breakiterator_th.cxx |   46 ++++++++-------------
 2 files changed, 21 insertions(+), 30 deletions(-)

New commits:
commit 2c1fb32e0b3f0c51edcbb861977d372ae4eaf5e4
Author: Khaled Hosny <khaledhosny at eglug.org>
Date:   Tue May 22 05:40:26 2018 +0200

    Use vector in BreakIterator_th instead of C arrays
    
    Change-Id: Ie93920bccfe5444e0066f8df85b4a9d2ff060a2d
    Reviewed-on: https://gerrit.libreoffice.org/54650
    Tested-by: Jenkins <ci at libreoffice.org>
    Reviewed-by: Noel Grandin <noel.grandin at collabora.co.uk>
    Reviewed-by: Eike Rathke <erack at redhat.com>

diff --git a/i18npool/inc/breakiterator_th.hxx b/i18npool/inc/breakiterator_th.hxx
index 5c0119fbe919..c2f3629d1bc8 100644
--- a/i18npool/inc/breakiterator_th.hxx
+++ b/i18npool/inc/breakiterator_th.hxx
@@ -45,9 +45,8 @@ public:
 
 private:
     OUString cachedText; // for cell index
-    sal_Int32* nextCellIndex;
-    sal_Int32* previousCellIndex;
-    sal_Int32 cellIndexSize;
+    std::vector<sal_Int32> m_aNextCellIndex;
+    std::vector<sal_Int32> m_aPreviousCellIndex;
 
     void makeIndex(const OUString& text, sal_Int32 pos);
 };
diff --git a/i18npool/source/breakiterator/breakiterator_th.cxx b/i18npool/source/breakiterator/breakiterator_th.cxx
index aa9d4e8b6ea5..a5ab63e9a63f 100644
--- a/i18npool/source/breakiterator/breakiterator_th.cxx
+++ b/i18npool/source/breakiterator/breakiterator_th.cxx
@@ -36,15 +36,12 @@ namespace i18npool {
  * Constructor.
  */
 BreakIterator_th::BreakIterator_th() :
-    cachedText(),
-    nextCellIndex( nullptr ),
-    previousCellIndex( nullptr ),
-    cellIndexSize( 512 )
+    cachedText()
 {
     cBreakIterator = "com.sun.star.i18n.BreakIterator_th";
     // to improve performance, alloc big enough memory in construct.
-    nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
-    previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
+    m_aNextCellIndex.assign(512, 0);
+    m_aPreviousCellIndex.assign(512, 0);
     lineRule=nullptr;
 }
 
@@ -53,8 +50,6 @@ BreakIterator_th::BreakIterator_th() :
  */
 BreakIterator_th::~BreakIterator_th()
 {
-    free(nextCellIndex);
-    free(previousCellIndex);
 }
 
 sal_Int32 SAL_CALL BreakIterator_th::previousCharacters( const OUString& Text,
@@ -66,12 +61,12 @@ sal_Int32 SAL_CALL BreakIterator_th::previousCharacters( const OUString& Text,
         if (nStartPos > 0) {    // for others to skip cell.
             makeIndex(Text, nStartPos);
 
-            if (nextCellIndex[nStartPos-1] == 0) // not a CTL character
+            if (m_aNextCellIndex[nStartPos-1] == 0) // not a CTL character
                 return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
                     nCharacterIteratorMode, nCount, nDone);
-            else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) {
+            else while (nCount > 0 && m_aNextCellIndex[nStartPos - 1] > 0) {
                 nCount--; nDone++;
-                nStartPos = previousCellIndex[nStartPos - 1];
+                nStartPos = m_aPreviousCellIndex[nStartPos - 1];
             }
         } else
             nStartPos = 0;
@@ -93,12 +88,12 @@ sal_Int32 SAL_CALL BreakIterator_th::nextCharacters(const OUString& Text,
         if (nStartPos < len) {
             makeIndex(Text, nStartPos);
 
-            if (nextCellIndex[nStartPos] == 0) // not a CTL character
+            if (m_aNextCellIndex[nStartPos] == 0) // not a CTL character
                 return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
                     nCharacterIteratorMode, nCount, nDone);
-            else while (nCount > 0 && nextCellIndex[nStartPos] > 0) {
+            else while (nCount > 0 && m_aNextCellIndex[nStartPos] > 0) {
                 nCount--; nDone++;
-                nStartPos = nextCellIndex[nStartPos];
+                nStartPos = m_aNextCellIndex[nStartPos];
             }
         } else
             nStartPos = len;
@@ -121,7 +116,7 @@ LineBreakResults SAL_CALL BreakIterator_th::getLineBreak(
                     rLocale, nMinBreakPos, hOptions, bOptions );
     if (lbr.breakIndex < Text.getLength()) {
         makeIndex(Text, lbr.breakIndex);
-        lbr.breakIndex = previousCellIndex[ lbr.breakIndex ];
+        lbr.breakIndex = m_aPreviousCellIndex[ lbr.breakIndex ];
     }
     return lbr;
 }
@@ -193,17 +188,14 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
 {
     if (Text != cachedText) {
         cachedText = Text;
-        if (cellIndexSize < cachedText.getLength()) {
-            cellIndexSize = cachedText.getLength();
-            free(nextCellIndex);
-            free(previousCellIndex);
-            nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
-            previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
+        if (m_aNextCellIndex.size() < size_t(cachedText.getLength())) {
+            m_aNextCellIndex.resize(cachedText.getLength());
+            m_aPreviousCellIndex.resize(cachedText.getLength());
         }
         // reset nextCell for new Text
-        memset(nextCellIndex, 0, cellIndexSize * sizeof(sal_Int32));
+        m_aNextCellIndex.assign(cachedText.getLength(), 0);
     }
-    else if (nStartPos >= Text.getLength() || nextCellIndex[nStartPos] > 0
+    else if (nStartPos >= Text.getLength() || m_aNextCellIndex[nStartPos] > 0
              || !is_Thai(Text[nStartPos]))
         return;
 
@@ -218,13 +210,13 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
     sal_Int32 start, end, pos;
     pos = start = end = startPos;
 
-    assert(endPos <= cellIndexSize);
+    assert(size_t(endPos) <= m_aNextCellIndex.size());
     while (pos < endPos) {
         end += getACell(str, start, endPos);
-        assert(end <= cellIndexSize);
+        assert(size_t(end) <= m_aNextCellIndex.size());
         while (pos < end) {
-            nextCellIndex[pos] = end;
-            previousCellIndex[pos] = start;
+            m_aNextCellIndex[pos] = end;
+            m_aPreviousCellIndex[pos] = start;
             pos++;
         }
         start = end;


More information about the Libreoffice-commits mailing list