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


The attached patch replaces usage of LinkList (declared as
DECLARE_LIST(LinkList, Link*) with std::list<Link>.

I used list<Link> instead of list<Link*> because 1) the elements of the
list were only ever used from within the .cxx file declaring the list
itself and 2) each element was already allocated on addition and
deallocated on removal, so I just made that more explicit by letting
std::list handle it.

As with all my patches, this is LGPLv3+/MPL.
From ee05143cb845bf7f82cf1a55b5e72f7a932946c0 Mon Sep 17 00:00:00 2001
From: Jonathan Callen <abcd@gentoo.org>
Date: Tue, 1 Feb 2011 01:32:54 -0500
Subject: [PATCH] Convert tools/list.hxx usage to std::list

---
 svtools/source/config/htmlcfg.cxx     |   18 ++++++++----------
 svtools/source/config/menuoptions.cxx |   33 +++++++++++++++------------------
 svtools/source/config/miscopt.cxx     |   22 +++++++++-------------
 3 files changed, 32 insertions(+), 41 deletions(-)

diff --git a/svtools/source/config/htmlcfg.cxx b/svtools/source/config/htmlcfg.cxx
index b44dfe2..2de1f14 100644
--- a/svtools/source/config/htmlcfg.cxx
+++ b/svtools/source/config/htmlcfg.cxx
@@ -33,9 +33,9 @@
 #include <svtools/parhtml.hxx>
 #include <unotools/syslocale.hxx>
 #include <tools/debug.hxx>
-#include <tools/list.hxx>
 #include <tools/link.hxx>
 #include <sal/macros.h>
+#include <list>
 
 // -----------------------------------------------------------------------
 #define HTMLCFG_UNKNOWN_TAGS                   0x01
@@ -54,13 +54,11 @@ using namespace com::sun::star::uno;
 
 static SvxHtmlOptions* pOptions = 0;
 
-DECLARE_LIST( LinkList, Link * )
-
 #define C2U(cChar) OUString::createFromAscii(cChar)
 
 struct HtmlOptions_Impl
 {
-    LinkList    aList;
+    ::std::list<Link> aList;
     sal_Int32  nFlags;
     sal_Int32  nExportMode;
     sal_Int32  aFontSizeArr[HTML_FONT_COUNT];
@@ -268,16 +266,16 @@ void      SvxHtmlOptions::Commit()
 
 void SvxHtmlOptions::AddListenerLink( const Link& rLink )
 {
-    pImp->aList.Insert( new Link( rLink ) );
+    pImp->aList.push_back( rLink );
 }
 
 void SvxHtmlOptions::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<pImp->aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = pImp->aList.begin(); iter != pImp->aList.end(); 
++iter )
     {
-        if ( (*pImp->aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete pImp->aList.Remove(n);
+            pImp->aList.erase(iter);
             break;
         }
     }
@@ -285,8 +283,8 @@ void SvxHtmlOptions::RemoveListenerLink( const Link& rLink )
 
 void SvxHtmlOptions::CallListeners()
 {
-    for ( USHORT n = 0; n < pImp->aList.Count(); ++n )
-        pImp->aList.GetObject(n)->Call( this );
+    for ( ::std::list<Link>::const_iterator iter = pImp->aList.begin(); iter != pImp->aList.end(); 
++iter )
+        iter->Call( this );
 }
 
 
diff --git a/svtools/source/config/menuoptions.cxx b/svtools/source/config/menuoptions.cxx
index e0b57c5..7703738 100644
--- a/svtools/source/config/menuoptions.cxx
+++ b/svtools/source/config/menuoptions.cxx
@@ -40,6 +40,8 @@
 #include <rtl/logfile.hxx>
 #include "itemholder2.hxx"
 
+#include <list>
+
 
//_________________________________________________________________________________________________________________
 //     namespaces
 
//_________________________________________________________________________________________________________________
@@ -71,8 +73,6 @@ using namespace ::com::sun::star::uno ;
 #define PROPERTYCOUNT                           4
 
 #include <tools/link.hxx>
-#include <tools/list.hxx>
-DECLARE_LIST( LinkList, Link * )
 
 
//_________________________________________________________________________________________________________________
 //     private declarations!
@@ -85,7 +85,7 @@ class SvtMenuOptions_Impl : public ConfigItem
     
//-------------------------------------------------------------------------------------------------------------
 
     private:
-        LinkList    aList;
+        ::std::list<Link> aList;
         sal_Bool       m_bDontHideDisabledEntries                      ;       /// cache 
"DontHideDisabledEntries" of Menu section
         sal_Bool       m_bFollowMouse                                          ;       /// cache 
"FollowMouse" of Menu section
         sal_Int16      m_nMenuIcons                                            ;       /// cache 
"MenuIcons" of Menu section
@@ -171,8 +171,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_bDontHideDisabledEntries = bState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != 
aList.end(); ++iter )
+                            iter->Call( this );
                         Commit();
                     }
 
@@ -180,8 +180,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_bFollowMouse = bState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != 
aList.end(); ++iter )
+                            iter->Call( this );
                         Commit();
                     }
 
@@ -189,8 +189,8 @@ class SvtMenuOptions_Impl : public ConfigItem
                     {
                         m_nMenuIcons = nState;
                         SetModified();
-                        for ( USHORT n=0; n<aList.Count(); n++ )
-                            aList.GetObject(n)->Call( this );
+                        for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != 
aList.end(); ++iter )
+                            iter->Call( this );
                         Commit();
                     }
 
@@ -300,9 +300,6 @@ SvtMenuOptions_Impl::~SvtMenuOptions_Impl()
     {
         Commit();
     }
-
-    for ( USHORT n=0; n<aList.Count(); )
-        delete aList.Remove(n);
 }
 
 
//*****************************************************************************************************************
@@ -353,8 +350,8 @@ void SvtMenuOptions_Impl::Notify( const Sequence< OUString >& seqPropertyNames )
     if ( bMenuSettingsChanged )
         m_nMenuIcons = bSystemMenuIcons ? 2 : bMenuIcons;
 
-    for ( USHORT n=0; n<aList.Count(); n++ )
-        aList.GetObject(n)->Call( this );
+    for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
+        iter->Call( this );
 }
 
 
//*****************************************************************************************************************
@@ -417,16 +414,16 @@ Sequence< OUString > SvtMenuOptions_Impl::impl_GetPropertyNames()
 
 void SvtMenuOptions_Impl::AddListenerLink( const Link& rLink )
 {
-    aList.Insert( new Link( rLink ) );
+    aList.push_back( rLink );
 }
 
 void SvtMenuOptions_Impl::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
     {
-        if ( (*aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete aList.Remove(n);
+            aList.erase(iter);
             break;
         }
     }
diff --git a/svtools/source/config/miscopt.cxx b/svtools/source/config/miscopt.cxx
index f5aa5db..81f1a84 100644
--- a/svtools/source/config/miscopt.cxx
+++ b/svtools/source/config/miscopt.cxx
@@ -39,7 +39,6 @@
 #include <com/sun/star/uno/Any.hxx>
 #include <com/sun/star/uno/Sequence.hxx>
 #include <tools/link.hxx>
-#include <tools/list.hxx>
 #include <tools/wldcrd.hxx>
 #include <tools/urlobj.hxx>
 
@@ -49,6 +48,8 @@
 #include <imgdef.hxx>
 #include <vcl/svapp.hxx>
 
+#include <list>
+
 
//_________________________________________________________________________________________________________________
 //     namespaces
 
//_________________________________________________________________________________________________________________
@@ -94,8 +95,6 @@ using namespace ::com::sun::star;
 
 #define VCL_TOOLBOX_STYLE_FLAT                         ((USHORT)0x0004) // from <vcl/toolbox.hxx>
 
-DECLARE_LIST( LinkList, Link * )
-
 
//_________________________________________________________________________________________________________________
 //     private declarations!
 
//_________________________________________________________________________________________________________________
@@ -107,7 +106,7 @@ class SvtMiscOptions_Impl : public ConfigItem
     
//-------------------------------------------------------------------------------------------------------------
 
     private:
-    LinkList    aList;
+    ::std::list<Link> aList;
     sal_Bool    m_bUseSystemFileDialog;
     sal_Bool    m_bIsUseSystemFileDialogRO;
     sal_Bool    m_bTryODMADialog;
@@ -469,9 +468,6 @@ SvtMiscOptions_Impl::~SvtMiscOptions_Impl()
     {
         Commit();
     }
-
-    for ( USHORT n=0; n<aList.Count(); )
-        delete aList.Remove(n);
 }
 
 static int lcl_MapPropertyName( const ::rtl::OUString rCompare,
@@ -580,16 +576,16 @@ void SvtMiscOptions_Impl::Load( const Sequence< OUString >& rPropertyNames )
 
 void SvtMiscOptions_Impl::AddListenerLink( const Link& rLink )
 {
-    aList.Insert( new Link( rLink ) );
+    aList.push_back( rLink );
 }
 
 void SvtMiscOptions_Impl::RemoveListenerLink( const Link& rLink )
 {
-    for ( USHORT n=0; n<aList.Count(); n++ )
+    for ( ::std::list<Link>::iterator iter = aList.begin(); iter != aList.end(); ++iter )
     {
-        if ( (*aList.GetObject(n) ) == rLink )
+        if ( *iter == rLink )
         {
-            delete aList.Remove(n);
+            aList.erase(iter);
             break;
         }
     }
@@ -597,8 +593,8 @@ void SvtMiscOptions_Impl::RemoveListenerLink( const Link& rLink )
 
 void SvtMiscOptions_Impl::CallListeners()
 {
-    for ( USHORT n = 0; n < aList.Count(); ++n )
-        aList.GetObject(n)->Call( this );
+    for ( ::std::list<Link>::const_iterator iter = aList.begin(); iter != aList.end(); ++iter )
+        iter->Call( this );
 }
 
 void SvtMiscOptions_Impl::SetToolboxStyle( sal_Int16 nStyle, bool _bSetModified )
-- 
1.7.4.rc3

Attachment: signature.asc
Description: OpenPGP digital signature


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.