Kaydet (Commit) 2c1fb32e authored tarafından Khaled Hosny's avatar Khaled Hosny Kaydeden (comit) Eike Rathke

Use vector in BreakIterator_th instead of C arrays

Change-Id: Ie93920bccfe5444e0066f8df85b4a9d2ff060a2d
Reviewed-on: https://gerrit.libreoffice.org/54650Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
Reviewed-by: 's avatarEike Rathke <erack@redhat.com>
üst 98908d79
...@@ -45,9 +45,8 @@ public: ...@@ -45,9 +45,8 @@ public:
private: private:
OUString cachedText; // for cell index OUString cachedText; // for cell index
sal_Int32* nextCellIndex; std::vector<sal_Int32> m_aNextCellIndex;
sal_Int32* previousCellIndex; std::vector<sal_Int32> m_aPreviousCellIndex;
sal_Int32 cellIndexSize;
void makeIndex(const OUString& text, sal_Int32 pos); void makeIndex(const OUString& text, sal_Int32 pos);
}; };
......
...@@ -36,15 +36,12 @@ namespace i18npool { ...@@ -36,15 +36,12 @@ namespace i18npool {
* Constructor. * Constructor.
*/ */
BreakIterator_th::BreakIterator_th() : BreakIterator_th::BreakIterator_th() :
cachedText(), cachedText()
nextCellIndex( nullptr ),
previousCellIndex( nullptr ),
cellIndexSize( 512 )
{ {
cBreakIterator = "com.sun.star.i18n.BreakIterator_th"; cBreakIterator = "com.sun.star.i18n.BreakIterator_th";
// to improve performance, alloc big enough memory in construct. // to improve performance, alloc big enough memory in construct.
nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32))); m_aNextCellIndex.assign(512, 0);
previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32))); m_aPreviousCellIndex.assign(512, 0);
lineRule=nullptr; lineRule=nullptr;
} }
...@@ -53,8 +50,6 @@ BreakIterator_th::BreakIterator_th() : ...@@ -53,8 +50,6 @@ BreakIterator_th::BreakIterator_th() :
*/ */
BreakIterator_th::~BreakIterator_th() BreakIterator_th::~BreakIterator_th()
{ {
free(nextCellIndex);
free(previousCellIndex);
} }
sal_Int32 SAL_CALL BreakIterator_th::previousCharacters( const OUString& Text, sal_Int32 SAL_CALL BreakIterator_th::previousCharacters( const OUString& Text,
...@@ -66,12 +61,12 @@ 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. if (nStartPos > 0) { // for others to skip cell.
makeIndex(Text, nStartPos); 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, return BreakIterator_Unicode::previousCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone); nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos - 1] > 0) { else while (nCount > 0 && m_aNextCellIndex[nStartPos - 1] > 0) {
nCount--; nDone++; nCount--; nDone++;
nStartPos = previousCellIndex[nStartPos - 1]; nStartPos = m_aPreviousCellIndex[nStartPos - 1];
} }
} else } else
nStartPos = 0; nStartPos = 0;
...@@ -93,12 +88,12 @@ sal_Int32 SAL_CALL BreakIterator_th::nextCharacters(const OUString& Text, ...@@ -93,12 +88,12 @@ sal_Int32 SAL_CALL BreakIterator_th::nextCharacters(const OUString& Text,
if (nStartPos < len) { if (nStartPos < len) {
makeIndex(Text, nStartPos); 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, return BreakIterator_Unicode::nextCharacters(Text, nStartPos, rLocale,
nCharacterIteratorMode, nCount, nDone); nCharacterIteratorMode, nCount, nDone);
else while (nCount > 0 && nextCellIndex[nStartPos] > 0) { else while (nCount > 0 && m_aNextCellIndex[nStartPos] > 0) {
nCount--; nDone++; nCount--; nDone++;
nStartPos = nextCellIndex[nStartPos]; nStartPos = m_aNextCellIndex[nStartPos];
} }
} else } else
nStartPos = len; nStartPos = len;
...@@ -121,7 +116,7 @@ LineBreakResults SAL_CALL BreakIterator_th::getLineBreak( ...@@ -121,7 +116,7 @@ LineBreakResults SAL_CALL BreakIterator_th::getLineBreak(
rLocale, nMinBreakPos, hOptions, bOptions ); rLocale, nMinBreakPos, hOptions, bOptions );
if (lbr.breakIndex < Text.getLength()) { if (lbr.breakIndex < Text.getLength()) {
makeIndex(Text, lbr.breakIndex); makeIndex(Text, lbr.breakIndex);
lbr.breakIndex = previousCellIndex[ lbr.breakIndex ]; lbr.breakIndex = m_aPreviousCellIndex[ lbr.breakIndex ];
} }
return lbr; return lbr;
} }
...@@ -193,17 +188,14 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos ...@@ -193,17 +188,14 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
{ {
if (Text != cachedText) { if (Text != cachedText) {
cachedText = Text; cachedText = Text;
if (cellIndexSize < cachedText.getLength()) { if (m_aNextCellIndex.size() < size_t(cachedText.getLength())) {
cellIndexSize = cachedText.getLength(); m_aNextCellIndex.resize(cachedText.getLength());
free(nextCellIndex); m_aPreviousCellIndex.resize(cachedText.getLength());
free(previousCellIndex);
nextCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
previousCellIndex = static_cast<sal_Int32*>(calloc(cellIndexSize, sizeof(sal_Int32)));
} }
// reset nextCell for new Text // 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])) || !is_Thai(Text[nStartPos]))
return; return;
...@@ -218,13 +210,13 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos ...@@ -218,13 +210,13 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
sal_Int32 start, end, pos; sal_Int32 start, end, pos;
pos = start = end = startPos; pos = start = end = startPos;
assert(endPos <= cellIndexSize); assert(size_t(endPos) <= m_aNextCellIndex.size());
while (pos < endPos) { while (pos < endPos) {
end += getACell(str, start, endPos); end += getACell(str, start, endPos);
assert(end <= cellIndexSize); assert(size_t(end) <= m_aNextCellIndex.size());
while (pos < end) { while (pos < end) {
nextCellIndex[pos] = end; m_aNextCellIndex[pos] = end;
previousCellIndex[pos] = start; m_aPreviousCellIndex[pos] = start;
pos++; pos++;
} }
start = end; start = end;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment