Re: [Libreoffice] [PATCH][EasyHacks] Remove some use of svarray stuff in SwScriptInfo

2011-02-10 Thread Caolán McNamara
On Tue, 2011-02-08 at 14:24 +, Nigel Hawkins wrote:
 Hi,
 
 The attached patch removes one use of SvBytes and SvXub_StrLens from
 SwScriptInfo.

bzzt...

-while ( nChg  rTxt.Len() || ( !aScriptChg.Count()  !
rTxt.Len() ) )
+while ( nChg  rTxt.Len() || ( !aScriptChanges.empty()  !
rTxt.Len() ) )

!Count() - !empty(), should have been empty(), fixed now.

C.

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


[Libreoffice] [PATCH][EasyHacks] Remove some use of svarray stuff in SwScriptInfo

2011-02-08 Thread Nigel Hawkins
Hi,

The attached patch removes one use of SvBytes and SvXub_StrLens from
SwScriptInfo.

There are still other uses in there to be replaced, but the bits don't
interact very much.

Changes under LGPLv3+/MPL

Nigel.
From 8d92a6e07a576a76b429f98c10ab48975a69768f Mon Sep 17 00:00:00 2001
From: Nigel Hawkins n.hawk...@gmx.com
Date: Tue, 8 Feb 2011 14:05:29 +
Subject: [PATCH 3/3] Remove some svArray usage in SwScriptInfo

---
 sw/source/core/inc/scriptinfo.hxx |   23 +++-
 sw/source/core/text/porlay.cxx|   52 
 2 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx
index 5b46b8d..ef3a365 100644
--- a/sw/source/core/inc/scriptinfo.hxx
+++ b/sw/source/core/inc/scriptinfo.hxx
@@ -99,8 +99,16 @@ public:
 class SwScriptInfo
 {
 private:
-SvXub_StrLens aScriptChg;
-SvBytes aScriptType;
+//! Records a single change in script type.
+struct ScriptChangeInfo
+{
+xub_StrLen position; //! Character position at which we change script
+BYTE   type; //! Script type (Latin/Asian/Complex) that we change to.
+inline ScriptChangeInfo(xub_StrLen pos, BYTE typ) : position(pos), type(typ) {};
+};
+//TODO - This is sorted, so should probably be a std::set rather than vector.
+//   But we also use random access (probably unnecessarily).
+std::vectorScriptChangeInfo aScriptChanges;
 SvXub_StrLens aDirChg;
 SvBytes aDirType;
 SvXub_StrLens aKashida;
@@ -357,16 +365,17 @@ inline void SwScriptInfo::SetInvalidity( const xub_StrLen nPos )
 if ( nPos  nInvalidityPos )
 nInvalidityPos = nPos;
 };
-inline USHORT SwScriptInfo::CountScriptChg() const { return aScriptChg.Count(); }
+
+inline USHORT SwScriptInfo::CountScriptChg() const { return aScriptChanges.size(); }
 inline xub_StrLen SwScriptInfo::GetScriptChg( const USHORT nCnt ) const
 {
-OSL_ENSURE( nCnt  aScriptChg.Count(),No ScriptChange today!);
-return aScriptChg[ nCnt ];
+OSL_ENSURE( nCnt  aScriptChanges.size(),No ScriptChange today!);
+return aScriptChanges[nCnt].position;
 }
 inline BYTE SwScriptInfo::GetScriptType( const xub_StrLen nCnt ) const
 {
-OSL_ENSURE( nCnt  aScriptChg.Count(),No ScriptType today!);
-return aScriptType[ nCnt ];
+OSL_ENSURE( nCnt  aScriptChanges.size(),No ScriptType today!);
+return aScriptChanges[nCnt].type;
 }
 
 inline USHORT SwScriptInfo::CountDirChg() const { return aDirChg.Count(); }
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 7c6a4b3..51d6c55 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -915,9 +915,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 //
 
 // remove invalid entries from script information arrays
-const USHORT nScriptRemove = aScriptChg.Count() - nCnt;
-aScriptChg.Remove( nCnt, nScriptRemove );
-aScriptType.Remove( nCnt, nScriptRemove );
+aScriptChanges.erase( aScriptChanges.begin() + nCnt, aScriptChanges.end() );
 
 // get the start of the last compression group
 USHORT nLastCompression = nChg;
@@ -981,8 +979,8 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 
 if ( nScript != nNextScript )
 {
-aScriptChg.Insert( nEnd, nCnt );
-aScriptType.Insert( nScript, nCnt++ );
+aScriptChanges.push_back( ScriptChangeInfo(nEnd, nScript) );
+nCnt++;
 nScript = nNextScript;
 }
 }
@@ -991,7 +989,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 // UPDATE THE SCRIPT INFO ARRAYS:
 //
 
-while ( nChg  rTxt.Len() || ( !aScriptChg.Count()  !rTxt.Len() ) )
+while ( nChg  rTxt.Len() || ( !aScriptChanges.empty()  !rTxt.Len() ) )
 {
 OSL_ENSURE( i18n::ScriptType::WEAK != nScript,
 Inserting WEAK into SwScriptInfo structure );
@@ -1032,18 +1030,18 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 if (nType == U_NON_SPACING_MARK || nType == U_ENCLOSING_MARK ||
 nType == U_COMBINING_SPACING_MARK )
 {
-aScriptChg.Insert( nChg - 1, nCnt );
+aScriptChanges.push_back( ScriptChangeInfo(nChg-1, nScript) );
 }
 else
 {
-aScriptChg.Insert( nChg, nCnt );
+aScriptChanges.push_back( ScriptChangeInfo(nChg, nScript) );
 }
 }
 else
 {
-aScriptChg.Insert( nChg, nCnt );
+aScriptChanges.push_back( ScriptChangeInfo(nChg, nScript) );
 }
-aScriptType.Insert( nScript, nCnt++ );
+++nCnt;
 
 // if current script is asian, we search for compressable characters
 // in this range
@@ -1360,37 +1358,33 @@ void SwScriptInfo::InitScriptInfo( const 

Re: [Libreoffice] [PATCH][EasyHacks] Remove some use of svarray stuff in SwScriptInfo

2011-02-08 Thread Nigel Hawkins
The attached patch removes some more SvBytes and SvXub_StrLens usage
from SwScriptInfo.

Changes under LGPLv3+/MPL

Nigel.
From bdbe75e3715a5e553c26edcefb09abff7ebf936b Mon Sep 17 00:00:00 2001
From: Nigel Hawkins n.hawk...@gmx.com
Date: Tue, 8 Feb 2011 15:05:14 +
Subject: [PATCH 4/4] Remove direction svArray usage in SwScriptInfo

---
 sw/source/core/inc/scriptinfo.hxx |   20 +---
 sw/source/core/text/porlay.cxx|   17 -
 2 files changed, 17 insertions(+), 20 deletions(-)

diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx
index ef3a365..f8cf486 100644
--- a/sw/source/core/inc/scriptinfo.hxx
+++ b/sw/source/core/inc/scriptinfo.hxx
@@ -109,8 +109,14 @@ private:
 //TODO - This is sorted, so should probably be a std::set rather than vector.
 //   But we also use random access (probably unnecessarily).
 std::vectorScriptChangeInfo aScriptChanges;
-SvXub_StrLens aDirChg;
-SvBytes aDirType;
+//! Records a single change in direction.
+struct DirectionChangeInfo
+{
+xub_StrLen position; //! Character position at which we change direction.
+BYTE   type; //! Direction that we change to.
+inline DirectionChangeInfo(xub_StrLen pos, BYTE typ) : position(pos), type(typ) {};
+};
+std::vectorDirectionChangeInfo aDirectionChanges;
 SvXub_StrLens aKashida;
 SvXub_StrLens aKashidaInvalid;
 SvXub_StrLens aNoKashidaLine;
@@ -378,16 +384,16 @@ inline BYTE SwScriptInfo::GetScriptType( const xub_StrLen nCnt ) const
 return aScriptChanges[nCnt].type;
 }
 
-inline USHORT SwScriptInfo::CountDirChg() const { return aDirChg.Count(); }
+inline USHORT SwScriptInfo::CountDirChg() const { return aDirectionChanges.size(); }
 inline xub_StrLen SwScriptInfo::GetDirChg( const USHORT nCnt ) const
 {
-OSL_ENSURE( nCnt  aDirChg.Count(),No DirChange today!);
-return aDirChg[ nCnt ];
+OSL_ENSURE( nCnt  aDirectionChanges.size(),No DirChange today!);
+return aDirectionChanges[ nCnt ].position;
 }
 inline BYTE SwScriptInfo::GetDirType( const xub_StrLen nCnt ) const
 {
-OSL_ENSURE( nCnt  aDirChg.Count(),No DirType today!);
-return aDirType[ nCnt ];
+OSL_ENSURE( nCnt  aDirectionChanges.size(),No DirType today!);
+return aDirectionChanges[ nCnt ].type;
 }
 
 inline USHORT SwScriptInfo::CountKashida() const { return aKashida.Count(); }
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index 51d6c55..b7db718 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -1304,9 +1304,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 #endif
 
 // remove invalid entries from direction information arrays
-const USHORT nDirRemove = aDirChg.Count();
-aDirChg.Remove( 0, nDirRemove );
-aDirType.Remove( 0, nDirRemove );
+aDirectionChanges.clear();
 
 // Perform Unicode Bidi Algorithm for text direction information
 bool bPerformUBA = UBIDI_LTR != nDefaultDir;
@@ -1326,7 +1324,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 // 1. All text in RTL runs will use the CTL font
 // #i89825# change the script type also to CTL (hennerdrewes)
 // 2. Text in embedded LTR runs that does not have any strong LTR characters (numbers!)
-for ( USHORT nDirIdx = 0; nDirIdx  aDirChg.Count(); ++nDirIdx )
+for ( USHORT nDirIdx = 0; nDirIdx  aDirectionChanges.size(); ++nDirIdx )
 {
 const BYTE nCurrDirType = GetDirType( nDirIdx );
 // nStart ist start of RTL run:
@@ -1395,10 +1393,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 void SwScriptInfo::UpdateBidiInfo( const String rTxt )
 {
 // remove invalid entries from direction information arrays
-const USHORT nDirRemove = aDirChg.Count();
-aDirChg.Remove( 0, nDirRemove );
-aDirType.Remove( 0, nDirRemove );
-
+aDirectionChanges.clear();
 //
 // Bidi functions from icu 2.0
 //
@@ -1413,14 +1408,10 @@ void SwScriptInfo::UpdateBidiInfo( const String rTxt )
 int32_t nStart = 0;
 int32_t nEnd;
 UBiDiLevel nCurrDir;
-// counter for direction information arrays
-USHORT nCntDir = 0;
-
 for ( USHORT nIdx = 0; nIdx  nCount; ++nIdx )
 {
 ubidi_getLogicalRun( pBidi, nStart, nEnd, nCurrDir );
-aDirChg.Insert( (USHORT)nEnd, nCntDir );
-aDirType.Insert( (BYTE)nCurrDir, nCntDir++ );
+aDirectionChanges.push_back( DirectionChangeInfo(nEnd, nCurrDir) );
 nStart = nEnd;
 }
 
-- 
1.7.0.4

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] [PATCH][EasyHacks] Remove some use of svarray stuff in SwScriptInfo

2011-02-08 Thread Nigel Hawkins
This patch removes the last use of SvBytes from SwScriptInfo. And should
be the last usage in sw.

Nigel
From 3d1e455ca3ede76235e769b65342f0f31d9f44ee Mon Sep 17 00:00:00 2001
From: Nigel Hawkins n.hawk...@gmx.com
Date: Tue, 8 Feb 2011 16:12:13 +
Subject: [PATCH 5/5] Remove compression svArray usage from SwScriptInfo

---
 sw/source/core/inc/scriptinfo.hxx |   26 --
 sw/source/core/text/porlay.cxx|   15 +++
 2 files changed, 19 insertions(+), 22 deletions(-)

diff --git a/sw/source/core/inc/scriptinfo.hxx b/sw/source/core/inc/scriptinfo.hxx
index f8cf486..4a70226 100644
--- a/sw/source/core/inc/scriptinfo.hxx
+++ b/sw/source/core/inc/scriptinfo.hxx
@@ -121,10 +121,16 @@ private:
 SvXub_StrLens aKashidaInvalid;
 SvXub_StrLens aNoKashidaLine;
 SvXub_StrLens aNoKashidaLineEnd;
-SvXub_StrLens aCompChg;
-SvXub_StrLens aCompLen;
 SvXub_StrLens aHiddenChg;
-SvBytes aCompType;
+//! Records a single change in compression.
+struct CompressionChangeInfo
+{
+xub_StrLen position; //! Character position where the change occurs.
+xub_StrLen length;   //! Length of the segment.
+BYTE   type; //! Type of compression that we change to.
+inline CompressionChangeInfo(xub_StrLen pos, xub_StrLen len, BYTE typ) : position(pos), length(len), type(typ) {};
+};
+std::vectorCompressionChangeInfo aCompressionChanges;
 xub_StrLen nInvalidityPos;
 BYTE nDefaultDir;
 
@@ -403,22 +409,22 @@ inline xub_StrLen SwScriptInfo::GetKashida( const USHORT nCnt ) const
 return aKashida[ nCnt ];
 }
 
-inline USHORT SwScriptInfo::CountCompChg() const { return aCompChg.Count(); };
+inline USHORT SwScriptInfo::CountCompChg() const { return aCompressionChanges.size(); };
 inline xub_StrLen SwScriptInfo::GetCompStart( const USHORT nCnt ) const
 {
-OSL_ENSURE( nCnt  aCompChg.Count(),No CompressionStart today!);
-return aCompChg[ nCnt ];
+OSL_ENSURE( nCnt  aCompressionChanges.size(),No CompressionStart today!);
+return aCompressionChanges[ nCnt ].position;
 }
 inline xub_StrLen SwScriptInfo::GetCompLen( const USHORT nCnt ) const
 {
-OSL_ENSURE( nCnt  aCompChg.Count(),No CompressionLen today!);
-return aCompLen[ nCnt ];
+OSL_ENSURE( nCnt  aCompressionChanges.size(),No CompressionLen today!);
+return aCompressionChanges[ nCnt ].length;
 }
 
 inline BYTE SwScriptInfo::GetCompType( const USHORT nCnt ) const
 {
-OSL_ENSURE( nCnt  aCompChg.Count(),No CompressionType today!);
-return aCompType[ nCnt ];
+OSL_ENSURE( nCnt  aCompressionChanges.size(),No CompressionType today!);
+return aCompressionChanges[ nCnt ].type;
 }
 
 inline USHORT SwScriptInfo::CountHiddenChg() const { return aHiddenChg.Count(); };
diff --git a/sw/source/core/text/porlay.cxx b/sw/source/core/text/porlay.cxx
index b7db718..8ca3535 100644
--- a/sw/source/core/text/porlay.cxx
+++ b/sw/source/core/text/porlay.cxx
@@ -931,10 +931,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 }
 
 // remove invalid entries from compression information arrays
-const USHORT nCompRemove = aCompChg.Count() - nCntComp;
-aCompChg.Remove( nCntComp, nCompRemove );
-aCompLen.Remove( nCntComp, nCompRemove );
-aCompType.Remove( nCntComp, nCompRemove );
+aCompressionChanges.erase(aCompressionChanges.begin() + nCntComp, aCompressionChanges.end() );
 
 // get the start of the last kashida group
 USHORT nLastKashida = nChg;
@@ -1085,10 +1082,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
  ePrevState != KANA )
 {
-aCompChg.Insert( nPrevChg, nCntComp );
-BYTE nTmpType = ePrevState;
-aCompType.Insert( nTmpType, nCntComp );
-aCompLen.Insert( nLastCompression - nPrevChg, nCntComp++ );
+aCompressionChanges.push_back( CompressionChangeInfo(nPrevChg, nLastCompression - nPrevChg, ePrevState) );
 }
 }
 
@@ -1106,10 +1100,7 @@ void SwScriptInfo::InitScriptInfo( const SwTxtNode rNode, sal_Bool bRTL )
 if ( CHARCOMPRESS_PUNCTUATION_KANA == aCompEnum ||
  ePrevState != KANA )
 {
-aCompChg.Insert( nPrevChg, nCntComp );
-BYTE nTmpType = ePrevState;
-aCompType.Insert( nTmpType, nCntComp );
-aCompLen.Insert( nLastCompression - nPrevChg, nCntComp++ );
+aCompressionChanges.push_back( CompressionChangeInfo(nPrevChg, nLastCompression - nPrevChg, ePrevState) );
 }
 }
 }
-- 
1.7.0.4

___
LibreOffice mailing list