From 96492aa362b35857a5835cd411815d3706e74fd8 Mon Sep 17 00:00:00 2001
From: Joseph Powers <jpowers27@cox.net>
Date: Sun, 19 Jun 2011 21:27:48 -0700
Subject: [PATCH] Replace List with std::vector< XPropertyEntry* >

---
 svx/inc/svx/xtable.hxx          |   29 +++++++-------
 svx/source/xoutdev/xtabbtmp.cxx |   12 +++--
 svx/source/xoutdev/xtabcolr.cxx |   12 +++--
 svx/source/xoutdev/xtabdash.cxx |   12 ++++--
 svx/source/xoutdev/xtabgrdt.cxx |   12 ++++--
 svx/source/xoutdev/xtabhtch.cxx |   12 ++++--
 svx/source/xoutdev/xtable.cxx   |   78 ++++++++++++++++++++++----------------
 svx/source/xoutdev/xtablend.cxx |   12 ++++--
 8 files changed, 106 insertions(+), 73 deletions(-)

diff --git a/svx/inc/svx/xtable.hxx b/svx/inc/svx/xtable.hxx
index 77eee35..afa1079 100644
--- a/svx/inc/svx/xtable.hxx
+++ b/svx/inc/svx/xtable.hxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -104,19 +104,19 @@ class XLineEndEntry : public XPropertyEntry
     basegfx::B2DPolyPolygon	aB2DPolyPolygon;
 
 public:
-    XLineEndEntry(const basegfx::B2DPolyPolygon& rB2DPolyPolygon, const String& rName) 
-    :	XPropertyEntry(rName), 
-        aB2DPolyPolygon(rB2DPolyPolygon) 
+    XLineEndEntry(const basegfx::B2DPolyPolygon& rB2DPolyPolygon, const String& rName)
+    :	XPropertyEntry(rName),
+        aB2DPolyPolygon(rB2DPolyPolygon)
     {}
 
-    void SetLineEnd(const basegfx::B2DPolyPolygon& rB2DPolyPolygon) 
-    { 
-        aB2DPolyPolygon = rB2DPolyPolygon; 
+    void SetLineEnd(const basegfx::B2DPolyPolygon& rB2DPolyPolygon)
+    {
+        aB2DPolyPolygon = rB2DPolyPolygon;
     }
 
     basegfx::B2DPolyPolygon& GetLineEnd()
-    { 
-        return aB2DPolyPolygon; 
+    {
+        return aB2DPolyPolygon;
     }
 };
 
@@ -241,6 +241,7 @@ public:
 // class XPropertyList
 // --------------------
 
+typedef ::std::vector< XPropertyEntry* > XPropertyEntryList_impl;
 class SVX_DLLPUBLIC XPropertyList
 {
 protected:
@@ -248,17 +249,17 @@ protected:
     String              aPath;
     XOutdevItemPool*    pXPool;
 
-    List                aList;
+    XPropertyEntryList_impl aList;
     List*               pBmpList;
 
     sal_Bool                bListDirty;
     sal_Bool                bBitmapsDirty;
     sal_Bool                bOwnPool;
 
-                        XPropertyList(  const String& rPath,
-                                        XOutdevItemPool* pXPool = NULL,
-                                        sal_uInt16 nInitSize = 16,
-                                        sal_uInt16 nReSize = 16 );
+                        XPropertyList(
+                            const String& rPath,
+                            XOutdevItemPool* pXPool = NULL
+                        );
                         XPropertyList( SvStream& rIn );
     void                Clear();
 
diff --git a/svx/source/xoutdev/xtabbtmp.cxx b/svx/source/xoutdev/xtabbtmp.cxx
index faa8387..6d638bc 100644
--- a/svx/source/xoutdev/xtabbtmp.cxx
+++ b/svx/source/xoutdev/xtabbtmp.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -148,10 +148,12 @@ Bitmap* XBitmapTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
 |*
 *************************************************************************/
 
-XBitmapList::XBitmapList( const String& rPath,
-                            XOutdevItemPool* pInPool,
-                            sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
-                XPropertyList( rPath, pInPool, nInitSize, nReSize)
+XBitmapList::XBitmapList(
+    const String& rPath,
+    XOutdevItemPool* pInPool,
+    sal_uInt16 /* nInitSize */,
+    sal_uInt16 /* nReSize */
+) : XPropertyList( rPath, pInPool )
 {
     // pBmpList = new List( nInitSize, nReSize );
 }
diff --git a/svx/source/xoutdev/xtabcolr.cxx b/svx/source/xoutdev/xtabcolr.cxx
index a0c8875..311f303 100644
--- a/svx/source/xoutdev/xtabcolr.cxx
+++ b/svx/source/xoutdev/xtabcolr.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -466,10 +466,12 @@ Bitmap* XColorTable::CreateBitmapForUI( long /*nIndex*/, sal_Bool /*bDelete*/)
 |*
 *************************************************************************/
 
-XColorList::XColorList( const String& rPath,
-                            XOutdevItemPool* pInPool,
-                            sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
-                XPropertyList( rPath, pInPool, nInitSize, nReSize)
+XColorList::XColorList(
+    const String& rPath,
+    XOutdevItemPool* pInPool,
+    sal_uInt16 /* nInitSize */,
+    sal_uInt16 /* nReSize */
+) : XPropertyList( rPath, pInPool )
 {
     // pBmpList = new List( nInitSize, nReSize );
 }
diff --git a/svx/source/xoutdev/xtabdash.cxx b/svx/source/xoutdev/xtabdash.cxx
index 4c3fc97..9f8bd33 100644
--- a/svx/source/xoutdev/xtabdash.cxx
+++ b/svx/source/xoutdev/xtabdash.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -201,7 +201,7 @@ void XDashList::impCreate()
         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
             : DRAWMODE_DEFAULT);
-    
+
         SdrModel* pSdrModel = new SdrModel();
         OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
         pSdrModel->GetItemPool().FreezeIdRanges();
@@ -240,8 +240,12 @@ void XDashList::impDestroy()
     }
 }
 
-XDashList::XDashList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
-:   XPropertyList(rPath, pInPool, nInitSize, nReSize),
+XDashList::XDashList(
+    const String& rPath,
+    XOutdevItemPool* pInPool,
+    sal_uInt16 nInitSize,
+    sal_uInt16 nReSize
+) : XPropertyList( rPath, pInPool ),
     mpData(0)
 {
     pBmpList = new List(nInitSize, nReSize);
diff --git a/svx/source/xoutdev/xtabgrdt.cxx b/svx/source/xoutdev/xtabgrdt.cxx
index 030b170..c950b14 100644
--- a/svx/source/xoutdev/xtabgrdt.cxx
+++ b/svx/source/xoutdev/xtabgrdt.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -193,7 +193,7 @@ void XGradientList::impCreate()
         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
             : DRAWMODE_DEFAULT);
-    
+
         SdrModel* pSdrModel = new SdrModel();
         OSL_ENSURE(0 != pSdrModel, "XGradientList: no SdrModel created!" );
         pSdrModel->GetItemPool().FreezeIdRanges();
@@ -222,8 +222,12 @@ void XGradientList::impDestroy()
     }
 }
 
-XGradientList::XGradientList( const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
-:   XPropertyList(rPath, pInPool, nInitSize, nReSize),
+XGradientList::XGradientList(
+    const String& rPath,
+    XOutdevItemPool* pInPool,
+    sal_uInt16 nInitSize,
+    sal_uInt16 nReSize
+) : XPropertyList( rPath, pInPool ),
     mpData(0)
 {
     pBmpList = new List(nInitSize, nReSize);
diff --git a/svx/source/xoutdev/xtabhtch.cxx b/svx/source/xoutdev/xtabhtch.cxx
index 569d159..4bc5254 100644
--- a/svx/source/xoutdev/xtabhtch.cxx
+++ b/svx/source/xoutdev/xtabhtch.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -195,7 +195,7 @@ void XHatchList::impCreate()
         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
             : DRAWMODE_DEFAULT);
-    
+
         SdrModel* pSdrModel = new SdrModel();
         OSL_ENSURE(0 != pSdrModel, "XDashList: no SdrModel created!" );
         pSdrModel->GetItemPool().FreezeIdRanges();
@@ -230,8 +230,12 @@ void XHatchList::impDestroy()
     }
 }
 
-XHatchList::XHatchList(const String& rPath, XOutdevItemPool* pInPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
-:   XPropertyList(rPath, pInPool, nInitSize, nReSize),
+XHatchList::XHatchList(
+    const String& rPath,
+    XOutdevItemPool* pInPool,
+    sal_uInt16 nInitSize,
+    sal_uInt16 nReSize
+) : XPropertyList( rPath, pInPool ),
     mpData(0)
 {
     pBmpList = new List(nInitSize, nReSize);
diff --git a/svx/source/xoutdev/xtable.cxx b/svx/source/xoutdev/xtable.cxx
index 18b4666..f089791 100644
--- a/svx/source/xoutdev/xtable.cxx
+++ b/svx/source/xoutdev/xtable.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -288,17 +288,16 @@ void XPropertyTable::SetName( const String& rString )
 |*
 *************************************************************************/
 
-XPropertyList::XPropertyList( const String& rPath,
-                                XOutdevItemPool* pInPool,
-                                sal_uInt16 nInitSize, sal_uInt16 nReSize ) :
-            aName			( pszStandard, 8 ),
-            aPath			( rPath ),
-            pXPool			( pInPool ),
-            aList			( nInitSize, nReSize ),
-            pBmpList		( NULL ),
-            bListDirty		( sal_True ),
-            bBitmapsDirty	( sal_True ),
-            bOwnPool		( sal_False )
+XPropertyList::XPropertyList(
+    const String& rPath,
+    XOutdevItemPool* pInPool
+) : aName			( pszStandard, 8 ),
+    aPath			( rPath ),
+    pXPool			( pInPool ),
+    pBmpList		( NULL ),
+    bListDirty		( sal_True ),
+    bBitmapsDirty	( sal_True ),
+    bOwnPool		( sal_False )
 {
     if( !pXPool )
     {
@@ -327,14 +326,12 @@ XPropertyList::XPropertyList( SvStream& /*rIn*/) :
 
 XPropertyList::~XPropertyList()
 {
-    XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
-    Bitmap* pBitmap = NULL;
-    for( sal_uIntPtr nIndex = 0; nIndex < aList.Count(); nIndex++ )
-    {
-        delete pEntry;
-        pEntry = (XPropertyEntry*)aList.Next();
+    for( size_t i = 0, n = aList.size(); i < n; ++i ) {
+        delete aList[ i ];
     }
+    aList.clear();
 
+    Bitmap* pBitmap = NULL;
     if( pBmpList )
     {
         pBitmap = (Bitmap*) pBmpList->First();
@@ -362,7 +359,10 @@ XPropertyList::~XPropertyList()
 
 void XPropertyList::Clear()
 {
-    aList.Clear();
+    for( size_t i = 0, n = aList.size(); i < n; ++i ) {
+        delete aList[ i ];
+    }
+    aList.clear();
     if( pBmpList )
         pBmpList->Clear();
 }
@@ -377,7 +377,7 @@ long XPropertyList::Count() const
         if( !( (XPropertyList*) this )->Load() )
             ( (XPropertyList*) this )->Create();
     }
-    return( aList.Count() );
+    return( aList.size() );
 }
 
 /*************************************************************************
@@ -394,7 +394,7 @@ XPropertyEntry* XPropertyList::Get( long nIndex, sal_uInt16 /*nDummy*/) const
         if( !( (XPropertyList*) this )->Load() )
             ( (XPropertyList*) this )->Create();
     }
-    return (XPropertyEntry*) aList.GetObject( (sal_uIntPtr) nIndex );
+    return ( (size_t)nIndex < aList.size() ) ? aList[ nIndex ] : NULL;
 }
 
 /*************************************************************************
@@ -411,15 +411,13 @@ long XPropertyList::Get(const XubString& rName)
         if( !Load() )
             Create();
     }
-    long nPos = 0;
-    XPropertyEntry* pEntry = (XPropertyEntry*)aList.First();
-    while (pEntry && pEntry->GetName() != rName)
-    {
-        nPos++;
-        pEntry = (XPropertyEntry*)aList.Next();
+
+    for( long i = 0, n = aList.size(); i < n; ++i ) {
+        if ( aList[ i ]->GetName() == rName ) {
+            return i;
+        }
     }
-    if (!pEntry) nPos = -1;
-    return nPos;
+    return -1;
 }
 
 /*************************************************************************
@@ -451,12 +449,17 @@ Bitmap* XPropertyList::GetBitmap( long nIndex ) const
 
 void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
 {
-    aList.Insert( pEntry, (sal_uIntPtr) nIndex );
+    if ( (size_t)nIndex < aList.size() ) {
+        aList.insert( aList.begin() + nIndex, pEntry );
+    } else {
+        aList.push_back( pEntry );
+    }
 
     if( pBmpList && !bBitmapsDirty )
     {
         Bitmap* pBmp = CreateBitmapForUI(
-                (sal_uIntPtr) nIndex < aList.Count() ? nIndex : aList.Count() - 1 );
+            (size_t)nIndex < aList.size() ? nIndex : aList.size() - 1
+        );
         pBmpList->Insert( pBmp, (sal_uIntPtr) nIndex );
     }
 }
@@ -469,7 +472,10 @@ void XPropertyList::Insert( XPropertyEntry* pEntry, long nIndex )
 
 XPropertyEntry* XPropertyList::Replace( XPropertyEntry* pEntry, long nIndex )
 {
-    XPropertyEntry* pOldEntry = (XPropertyEntry*) aList.Replace( pEntry, (sal_uIntPtr) nIndex );
+    XPropertyEntry* pOldEntry = (size_t)nIndex < aList.size() ? aList[ nIndex ] : NULL;
+    if ( pOldEntry ) {
+        aList[ nIndex ] = pEntry;
+    }
 
     if( pBmpList && !bBitmapsDirty )
     {
@@ -495,7 +501,13 @@ XPropertyEntry* XPropertyList::Remove( long nIndex, sal_uInt16 /*nDummy*/)
         if( pOldBmp )
             delete pOldBmp;
     }
-    return (XPropertyEntry*) aList.Remove( (sal_uIntPtr) nIndex );
+
+    XPropertyEntry* pEntry = NULL;
+    if ( (size_t)nIndex < aList.size() ) {
+        pEntry = aList[ nIndex ];
+        aList.erase( aList.begin() + nIndex );
+    }
+    return pEntry;
 }
 
 /************************************************************************/
diff --git a/svx/source/xoutdev/xtablend.cxx b/svx/source/xoutdev/xtablend.cxx
index bdcd65a..b48a1d7 100644
--- a/svx/source/xoutdev/xtablend.cxx
+++ b/svx/source/xoutdev/xtablend.cxx
@@ -2,7 +2,7 @@
 /*************************************************************************
  *
  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
- * 
+ *
  * Copyright 2000, 2010 Oracle and/or its affiliates.
  *
  * OpenOffice.org - a multi-platform office productivity suite
@@ -208,7 +208,7 @@ void XLineEndList::impCreate()
         pVirDev->SetDrawMode(rStyleSettings.GetHighContrastMode()
             ? DRAWMODE_SETTINGSLINE | DRAWMODE_SETTINGSFILL | DRAWMODE_SETTINGSTEXT | DRAWMODE_SETTINGSGRADIENT
             : DRAWMODE_DEFAULT);
-    
+
         SdrModel* pSdrModel = new SdrModel();
         OSL_ENSURE(0 != pSdrModel, "XLineEndList: no SdrModel created!" );
         pSdrModel->GetItemPool().FreezeIdRanges();
@@ -247,8 +247,12 @@ void XLineEndList::impDestroy()
     }
 }
 
-XLineEndList::XLineEndList(const String& rPath, XOutdevItemPool* _pXPool, sal_uInt16 nInitSize, sal_uInt16 nReSize)
-:	XPropertyList(rPath, _pXPool, nInitSize, nReSize),
+XLineEndList::XLineEndList(
+    const String& rPath,
+    XOutdevItemPool* _pXPool,
+    sal_uInt16 nInitSize,
+    sal_uInt16 nReSize
+) :	XPropertyList( rPath, _pXPool ),
     mpData(0)
 {
     pBmpList = new List(nInitSize, nReSize);
-- 
1.7.5

