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


Hi.

I converted the SV_DECL_VARARR_SORT and SV_IMPL_VARARR_SORT with ::std::set.
I also made some optimization (cppcheck).

Could you please check this patch and push it into libreoffice.

License statement is on file.

Thanks in advance
Bartosz
diff --git a/editeng/source/editeng/impedit.hxx b/editeng/source/editeng/impedit.hxx
index 1c008fb..417415e 100644
--- a/editeng/source/editeng/impedit.hxx
+++ b/editeng/source/editeng/impedit.hxx
@@ -906,7 +906,7 @@ public:
     LanguageType        GetDefaultLanguage() const { return eDefLanguage; }
 
 
-    LanguageType        GetLanguage( const EditSelection rSelection ) const;
+    LanguageType        GetLanguage( const EditSelection &rSelection ) const;
     LanguageType        GetLanguage( const EditPaM& rPaM, sal_uInt16* pEndPos = NULL ) const;
     ::com::sun::star::lang::Locale GetLocale( const EditPaM& rPaM ) const;
 
@@ -946,12 +946,12 @@ public:
     //adds one or more portions of text to the SpellPortions depending on language changes
     void            AddPortionIterated(
                         EditView& rEditView,
-                        const EditSelection rSel,
+                        const EditSelection &rSel,
                         ::com::sun::star::uno::Reference< 
::com::sun::star::linguistic2::XSpellAlternatives > xAlt,
                         ::svx::SpellPortions& rToFill);
     //adds one portion to the SpellPortions
     void            AddPortion(
-                        const EditSelection rSel,
+                        const EditSelection &rSel,
                         ::com::sun::star::uno::Reference< 
::com::sun::star::linguistic2::XSpellAlternatives > xAlt,
                         ::svx::SpellPortions& rToFill,
                         bool bIsField );
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 719a8753..b32cdc3 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -68,6 +68,7 @@
 
 #include <editeng/unolingu.hxx>
 
+#include <set>
 #include <math.h>
 #include <vcl/svapp.hxx>
 #include <vcl/metric.hxx>
@@ -86,9 +87,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
@@ -2252,14 +2250,14 @@ sal_uInt16 ImpEditEngine::SplitTextPortion( ParaPortion* pPortion, 
sal_uInt16 nP
     return nSplitPortion;
 }
 
-void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, sal_uInt16& rStart /* , 
sal_Bool bCreateBlockPortions */ )
+void ImpEditEngine::CreateTextPortions( ParaPortion* pParaPortion, sal_uInt16& rStart )
 {
     sal_uInt16 nStartPos = rStart;
     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_uInt32 > aPositions;
+    aPositions.insert( 0 );
 
     sal_uInt16 nAttr = 0;
     EditCharAttrib* pAttrib = GetAttrib( pNode->GetCharAttribs().GetAttribs(), nAttr );
@@ -2267,23 +2265,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,11 +2290,11 @@ 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:
@@ -2329,18 +2327,16 @@ 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 );
+    aPositions.insert( nPortionStart );
 
-    sal_uInt16 nInvPos;
-#ifdef DBG_UTIL
-    sal_Bool bFound =
-#endif
-                        aPositions.Seek_Entry( nPortionStart, &nInvPos );
+    ::std::set< sal_uInt32 >::iterator nInvPos = aPositions.find(  nPortionStart );
+    DBG_ASSERT( (nInvPos != aPositions.end()), "InvPos ?!" );
 
-    DBG_ASSERT( bFound && ( nInvPos < (aPositions.Count()-1) ), "InvPos ?!" );
-    for ( sal_uInt16 i = nInvPos+1; i < aPositions.Count(); i++ )
+    ::std::set< sal_uInt32 >::iterator i = nInvPos;
+    i++;
+       while ( i != aPositions.end() )
     {
-        TextPortion* pNew = new TextPortion( (sal_uInt16)aPositions[i] - 
(sal_uInt16)aPositions[i-1] );
+        TextPortion* pNew = new TextPortion( static_cast<sal_uInt16>(*i++) - 
static_cast<sal_uInt16>(*nInvPos++) );
         pParaPortion->GetTextPortions().Insert( pNew, pParaPortion->GetTextPortions().Count());
     }
 
@@ -3361,12 +3357,6 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point 
aSta
                                                 }
                                             }
                                         }
-
-                                        // comment
-
-
-
-
                                     }
 
                                     if ( GetStatus().DoOnlineSpelling() && 
!pPortion->GetNode()->GetWrongList()->empty() && pTextPortion->GetLen() )
@@ -3391,8 +3381,8 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, Rectangle aClipRec, Point 
aSta
 
                                 pOutDev->Pop();
 
-                                if ( pTmpDXArray )
-                                    delete[] pTmpDXArray;
+                                //The C++ language guarantees that delete p will do nothing if p 
is equal to NULL.
+                                delete[] pTmpDXArray;
 
                                 if ( pTextPortion->GetKind() == PORTIONKIND_FIELD )
                                 {
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index f76b0ca..043a879 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -1983,7 +1983,7 @@ bool ImpEditEngine::SpellSentence(EditView& rEditView,
 
 // Adds one portion to the SpellPortions
 void ImpEditEngine::AddPortion(
-                            const EditSelection rSel,
+                            const EditSelection& rSel,
                             uno::Reference< XSpellAlternatives > xAlt,
                                 ::svx::SpellPortions& rToFill,
                                 bool bIsField)
@@ -2007,7 +2007,7 @@ void ImpEditEngine::AddPortion(
 // Adds one or more portions of text to the SpellPortions depending on language changes
 void ImpEditEngine::AddPortionIterated(
                             EditView& rEditView,
-                            const EditSelection rSel,
+                            const EditSelection& rSel,
                             Reference< XSpellAlternatives > xAlt,
                                 ::svx::SpellPortions& rToFill)
 {
diff --git a/svtools/source/edit/texteng.cxx b/svtools/source/edit/texteng.cxx
index 74c4119..8c17c3d 100644
--- a/svtools/source/edit/texteng.cxx
+++ b/svtools/source/edit/texteng.cxx
@@ -62,6 +62,7 @@
 #include <vcl/unohelp.hxx>
 #include <vcl/metric.hxx>
 
+#include <set>
 #include <unicode/ubidi.h>
 
 using namespace ::com::sun::star;
@@ -70,10 +71,6 @@ using namespace ::rtl;
 
 typedef TextView* TextViewPtr;
 SV_DECL_PTRARR( TextViews, TextViewPtr, 0 )
-// SV_IMPL_PTRARR( TextViews, TextViewPtr );
-
-SV_DECL_VARARR_SORT( TESortedPositions, sal_uLong, 16 )
-SV_IMPL_VARARR_SORT( TESortedPositions, sal_uLong )
 
 #define RESDIFF     10
 #define SCRLRANGE   20      // 1/20 der Breite/Hoehe scrollen, wenn im QueryDrop
@@ -1822,9 +1819,9 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
     TextNode* pNode = pTEParaPortion->GetNode();
     DBG_ASSERT( pNode->GetText().Len(), "CreateTextPortions sollte nicht fuer leere Absaetze 
verwendet werden!" );
 
-    TESortedPositions aPositions;
+    ::std::set< sal_uLong > aPositions;
     sal_uLong nZero = 0;
-    aPositions.Insert( nZero );
+    aPositions.insert( nZero );
 
     sal_uInt16 nAttribs = pNode->GetCharAttribs().Count();
     for ( sal_uInt16 nAttr = 0; nAttr < nAttribs; nAttr++ )
@@ -1833,14 +1830,14 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
 
         // Start und Ende in das Array eintragen...
         // Die InsertMethode laesst keine doppelten Werte zu....
-        aPositions.Insert( pAttrib->GetStart() );
-        aPositions.Insert( pAttrib->GetEnd() );
+        aPositions.insert( pAttrib->GetStart() );
+        aPositions.insert( pAttrib->GetEnd() );
     }
-    aPositions.Insert( pNode->GetText().Len() );
+    aPositions.insert( pNode->GetText().Len() );
 
     const TEWritingDirectionInfos& rWritingDirections = pTEParaPortion->GetWritingDirectionInfos();
     for ( sal_uInt16 nD = 0; nD < rWritingDirections.Count(); nD++ )
-        aPositions.Insert( rWritingDirections[nD].nStartPos );
+        aPositions.insert( rWritingDirections[nD].nStartPos );
 
     if ( mpIMEInfos && mpIMEInfos->pAttribs && ( mpIMEInfos->aPos.GetPara() == nPara ) )
     {
@@ -1849,7 +1846,7 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
         {
             if ( mpIMEInfos->pAttribs[n] != nLastAttr )
             {
-                aPositions.Insert( mpIMEInfos->aPos.GetIndex() + n );
+                aPositions.insert( mpIMEInfos->aPos.GetIndex() + n );
                 nLastAttr = mpIMEInfos->pAttribs[n];
             }
         }
@@ -1858,13 +1855,13 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
     sal_uInt16 nTabPos = pNode->GetText().Search( '\t', 0 );
     while ( nTabPos != STRING_NOTFOUND )
     {
-        aPositions.Insert( nTabPos );
-        aPositions.Insert( nTabPos + 1 );
+        aPositions.insert( nTabPos );
+        aPositions.insert( nTabPos + 1 );
         nTabPos = pNode->GetText().Search( '\t', nTabPos+1 );
     }
 
     // Ab ... loeschen:
-    // Leider muss die Anzahl der TextPortions mit aPositions.Count()
+    // Leider muss die Anzahl der TextPortions mit aPositions.size()
     // nicht uebereinstimmen, da evtl. Zeilenumbrueche...
     sal_uInt16 nPortionStart = 0;
     sal_uInt16 nInvPortion = 0;
@@ -1880,7 +1877,7 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
             break;
         }
     }
-    DBG_ASSERT( nP < pTEParaPortion->GetTextPortions().Count() || 
!pTEParaPortion->GetTextPortions().Count(), "Nichts zum loeschen: CreateTextPortions" );
+    DBG_ASSERT( nP < pTEParaPortion->GetTextPortions().Count() || 
!pTEParaPortion->GetTextPortions().Count(), "Nothing to Delete: CreateTextPortions" );
     if ( nInvPortion && ( 
nPortionStart+pTEParaPortion->GetTextPortions().GetObject(nInvPortion)->GetLen() > nStartPos ) )
     {
         // lieber eine davor...
@@ -1891,29 +1888,26 @@ void TextEngine::CreateTextPortions( sal_uLong nPara, sal_uInt16 nStartPos )
     }
     pTEParaPortion->GetTextPortions().DeleteFromPortion( nInvPortion );
 
-    // Eine Portion kann auch durch einen Zeilenumbruch entstanden sein:
-    aPositions.Insert( nPortionStart );
-
-    sal_uInt16 nInvPos;
-    #ifdef DBG_UTIL
-    sal_Bool bFound =
-    #endif
-        aPositions.Seek_Entry( nPortionStart, &nInvPos );
-    DBG_ASSERT( bFound && ( nInvPos < (aPositions.Count()-1) ), "InvPos ?!" );
-    for ( sal_uInt16 i = nInvPos+1; i < aPositions.Count(); i++ )
+    // A portion may be formed by a line break:
+    aPositions.insert( nPortionStart );
+ 
+    std::set< sal_uLong >::iterator nInvPos = aPositions.find( nPortionStart );
+    DBG_ASSERT( (nInvPos != aPositions.end()), "InvPos ?!" );
+    std::set< sal_uLong >::iterator i = nInvPos;
+    i++;
+    while ( i != aPositions.end() )
     {
-        TETextPortion* pNew = new TETextPortion( (sal_uInt16)aPositions[i] - 
(sal_uInt16)aPositions[i-1] );
+        TETextPortion* pNew = new TETextPortion( static_cast< sal_uInt16 >(*i++) - static_cast< 
sal_uInt16 >(*nInvPos++) );
         pTEParaPortion->GetTextPortions().Insert( pNew, pTEParaPortion->GetTextPortions().Count());
     }
-
-    DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Keine Portions?!" );
+    DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "No Portions?!" );
 }
 
 void TextEngine::RecalcTextPortion( sal_uLong nPara, sal_uInt16 nStartPos, short nNewChars )
 {
     TEParaPortion* pTEParaPortion = mpTEParaPortions->GetObject( nPara );
-    DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Keine Portions!" );
-    DBG_ASSERT( nNewChars, "RecalcTextPortion mit Diff == 0" );
+    DBG_ASSERT( pTEParaPortion->GetTextPortions().Count(), "Do Portions not exists?" );
+    DBG_ASSERT( nNewChars, "RecalcTextPortion with Diff == 0" );
 
     TextNode* const pNode = pTEParaPortion->GetNode();
     if ( nNewChars > 0 )
@@ -1930,9 +1924,6 @@ void TextEngine::RecalcTextPortion( sal_uLong nPara, sal_uInt16 nStartPos, 
short
             sal_uInt16 nNewPortionPos = 0;
             if ( nStartPos )
                 nNewPortionPos = SplitTextPortion( nPara, nStartPos ) + 1;
-//          else if ( ( pTEParaPortion->GetTextPortions().Count() == 1 ) &&
-//                      !pTEParaPortion->GetTextPortions()[0]->GetLen() )
-//              pTEParaPortion->GetTextPortions().Reset();  // DummyPortion
 
             // Eine leere Portion kann hier stehen, wenn der Absatz leer war,
             // oder eine Zeile durch einen harten Zeilenumbruch entstanden ist.

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.