Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


Hi there,

This is my first STL C++ patch. ( I also wanted to do some conversion. )
Please review / comment / enjoy.

Matus
From f84c7a703a2329729b14bd4b99fc16cfcea25a7b Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Mat=C3=BA=C5=A1=20Kukan?= <matus.kukan@gmail.com>
Date: Thu, 1 Mar 2012 21:59:12 +0100
Subject: [PATCH] replace one instance of SV_DECL_VARARR_SORT with std::set

---
 editeng/source/editeng/impedit3.cxx |   38 +++++++++++++---------------------
 1 files changed, 15 insertions(+), 23 deletions(-)

diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 350a5d1..ff904e5 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -86,9 +86,6 @@ using namespace ::com::sun::star::uno;
 using namespace ::com::sun::star::beans;
 using namespace ::com::sun::star::linguistic2;
 
-SV_DECL_VARARR_SORT( SortedPositions, sal_uInt32, 16 )
-SV_IMPL_VARARR_SORT( SortedPositions, sal_uInt32 );
-
 #define CH_HYPH     '-'
 
 #define RESDIFF     10
@@ -2258,8 +2255,8 @@ void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, 
sal_uInt16& r
     ContentNode* pNode = pParaPortion->GetNode();
     DBG_ASSERT( pNode->Len(), "CreateTextPortions should not be used for empty paragraphs!" );
 
-    SortedPositions aPositions;
-    aPositions.Insert( (sal_uInt32) 0 );
+    std::set<sal_uInt16> aPositions;
+    aPositions.insert(0);
 
     sal_uInt16 nAttr = 0;
     EditCharAttrib* pAttrib = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
@@ -2267,23 +2264,23 @@ void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, 
sal_uInt16& r
     {
         // Insert Start and End into the Array...
         // The Insert method does not allow for duplicate values....
-        aPositions.Insert( pAttrib->GetStart() );
-        aPositions.Insert( pAttrib->GetEnd() );
+        aPositions.insert( pAttrib->GetStart() );
+        aPositions.insert( pAttrib->GetEnd() );
         nAttr++;
         pAttrib = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
     }
-    aPositions.Insert( pNode->Len() );
+    aPositions.insert( pNode->Len() );
 
     if ( pParaPortion->aScriptInfos.empty() )
         ((ImpEditEngine*)this)->InitScriptTypes( GetParaPortions().GetPos( pParaPortion ) );
 
     const ScriptTypePosInfos& rTypes = pParaPortion->aScriptInfos;
     for ( size_t nT = 0; nT < rTypes.size(); nT++ )
-        aPositions.Insert( rTypes[nT].nStartPos );
+        aPositions.insert( rTypes[nT].nStartPos );
 
     const WritingDirectionInfos& rWritingDirections = pParaPortion->aWritingDirectionInfos;
     for ( size_t nD = 0; nD < rWritingDirections.size(); nD++ )
-        aPositions.Insert( rWritingDirections[nD].nStartPos );
+        aPositions.insert( rWritingDirections[nD].nStartPos );
 
     if ( mpIMEInfos && mpIMEInfos->nLen && mpIMEInfos->pAttribs && ( mpIMEInfos->aPos.GetNode() == 
pNode ) )
     {
@@ -2292,16 +2289,16 @@ void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, 
sal_uInt16& r
         {
             if ( mpIMEInfos->pAttribs[n] != nLastAttr )
             {
-                aPositions.Insert( mpIMEInfos->aPos.GetIndex() + n );
+                aPositions.insert( mpIMEInfos->aPos.GetIndex() + n );
                 nLastAttr = mpIMEInfos->pAttribs[n];
             }
         }
-        aPositions.Insert( mpIMEInfos->aPos.GetIndex() + mpIMEInfos->nLen );
+        aPositions.insert( mpIMEInfos->aPos.GetIndex() + mpIMEInfos->nLen );
     }
 
     // From ... Delete:
     // Unfortunately, the number of text portions does not have to match
-    // aPositions.Count(), since there might be line breaks...
+    // aPositions.size(), since there might be line breaks...
     sal_uInt16 nPortionStart = 0;
     sal_uInt16 nInvPortion = 0;
     sal_uInt16 nP;
@@ -2329,18 +2326,13 @@ void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, 
sal_uInt16& r
     pParaPortion->GetTextPortions().DeleteFromPortion( nInvPortion );
 
     // A portion may also have been formed by a line break:
-    aPositions.Insert( nPortionStart );
-
-    sal_uInt16 nInvPos;
-#ifdef DBG_UTIL
-    sal_Bool bFound =
-#endif
-                        aPositions.Seek_Entry( nPortionStart, &nInvPos );
+    std::set<sal_uInt16>::const_iterator aPosIt = aPositions.insert( nPortionStart ).first;
+    std::set<sal_uInt16>::const_iterator aPrevPosIt = aPosIt++;
 
-    DBG_ASSERT( bFound && ( nInvPos < (aPositions.Count()-1) ), "InvPos ?!" );
-    for ( sal_uInt16 i = nInvPos+1; i < aPositions.Count(); i++ )
+    DBG_ASSERT( aPosIt != aPositions.end(), "InvPos ?!" );
+    for ( ; aPosIt != aPositions.end(); ++aPosIt, ++aPrevPosIt )
     {
-        TextPortion* pNew = new TextPortion( (sal_uInt16)aPositions[i] - 
(sal_uInt16)aPositions[i-1] );
+        TextPortion* pNew = new TextPortion( (*aPosIt) - (*aPrevPosIt) );
         pParaPortion->GetTextPortions().Insert( pNew, pParaPortion->GetTextPortions().Count());
     }
 
-- 
1.7.1


Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.