diff options
author | Noel Grandin <noel@peralex.com> | 2015-10-27 15:12:58 +0200 |
---|---|---|
committer | Michael Stahl <mstahl@redhat.com> | 2015-10-27 15:35:36 +0000 |
commit | 623f5b26ffd77041d0b06d7ce9c3b32d05625440 (patch) | |
tree | ecd905d6657147b1c5a074b4d33f914f0039440c /sfx2 | |
parent | 446f17f6c1f98b17ceb6750f5dc67a27330d1351 (diff) |
don't allocate rtl::Reference or SvRef on the heap
There is no point, since it's the size of a pointer anyway
Found by temporarily making their 'operator new' methods
deleted.
Change-Id: I265e40ce93ad4bad08b4f0bd49db08929e44b7d6
Reviewed-on: https://gerrit.libreoffice.org/19628
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/appl/fileobj.cxx | 15 | ||||
-rw-r--r-- | sfx2/source/appl/fileobj.hxx | 16 | ||||
-rw-r--r-- | sfx2/source/appl/linkmgr2.cxx | 51 |
3 files changed, 36 insertions, 46 deletions
diff --git a/sfx2/source/appl/fileobj.cxx b/sfx2/source/appl/fileobj.cxx index 70e53b2c0e59..e3ff4da09153 100644 --- a/sfx2/source/appl/fileobj.cxx +++ b/sfx2/source/appl/fileobj.cxx @@ -48,7 +48,7 @@ SvFileObject::SvFileObject() : nPostUserEventId(0) - , pDelMed(NULL) + , mxDelMed() , pOldParent(NULL) , nType(FILETYPE_TEXT) , bLoadAgain(true) @@ -73,7 +73,6 @@ SvFileObject::~SvFileObject() } if (nPostUserEventId) Application::RemoveUserEvent(nPostUserEventId); - delete pDelMed; } bool SvFileObject::GetData( ::com::sun::star::uno::Any & rData, @@ -485,22 +484,18 @@ IMPL_LINK_NOARG_TYPED( SvFileObject, LoadGrfReady_Impl, void*, void ) if( xMed.Is() ) { xMed->SetDoneLink( Link<void*,void>() ); - pDelMed = new tools::SvRef<SfxMedium>(xMed); + mxDelMed = xMed; nPostUserEventId = Application::PostUserEvent( - LINK( this, SvFileObject, DelMedium_Impl ), - pDelMed); + LINK( this, SvFileObject, DelMedium_Impl )); xMed.Clear(); } } } -IMPL_LINK_TYPED( SvFileObject, DelMedium_Impl, void*, p, void ) +IMPL_LINK_NOARG_TYPED( SvFileObject, DelMedium_Impl, void*, void ) { - tools::SvRef<SfxMedium>* deleteMedium = static_cast<tools::SvRef<SfxMedium>*>(p); nPostUserEventId = 0; - assert(pDelMed == deleteMedium); - pDelMed = NULL; - delete deleteMedium; + mxDelMed.Clear(); } IMPL_LINK_TYPED( SvFileObject, DialogClosedHdl, sfx2::FileDialogHelper*, _pFileDlg, void ) diff --git a/sfx2/source/appl/fileobj.hxx b/sfx2/source/appl/fileobj.hxx index bad1ddde0b8e..6ba78b2d8071 100644 --- a/sfx2/source/appl/fileobj.hxx +++ b/sfx2/source/appl/fileobj.hxx @@ -28,14 +28,14 @@ namespace sfx2 { class FileDialogHelper; } class SvFileObject : public sfx2::SvLinkSource { - OUString sFileNm; - OUString sFilter; - OUString sReferer; - Link<const OUString&, void> aEndEditLink; - tools::SvRef<SfxMedium> xMed; - ImplSVEvent* nPostUserEventId; - tools::SvRef<SfxMedium>* pDelMed; - VclPtr<vcl::Window> pOldParent; + OUString sFileNm; + OUString sFilter; + OUString sReferer; + Link<const OUString&, void> aEndEditLink; + tools::SvRef<SfxMedium> xMed; + ImplSVEvent* nPostUserEventId; + tools::SvRef<SfxMedium> mxDelMed; + VclPtr<vcl::Window> pOldParent; sal_uInt8 nType; diff --git a/sfx2/source/appl/linkmgr2.cxx b/sfx2/source/appl/linkmgr2.cxx index a0f60fab23a6..12a04bd02d6f 100644 --- a/sfx2/source/appl/linkmgr2.cxx +++ b/sfx2/source/appl/linkmgr2.cxx @@ -74,13 +74,12 @@ LinkManager::~LinkManager() { for( size_t n = 0; n < aLinkTbl.size(); ++n) { - tools::SvRef<SvBaseLink>* pTmp = aLinkTbl[ n ]; - if( pTmp->Is() ) + tools::SvRef<SvBaseLink>& rTmp = aLinkTbl[ n ]; + if( rTmp.Is() ) { - (*pTmp)->Disconnect(); - (*pTmp)->SetLinkManager( NULL ); + rTmp->Disconnect(); + rTmp->SetLinkManager( NULL ); } - delete pTmp; } } @@ -111,19 +110,18 @@ void LinkManager::Remove( SvBaseLink *pLink ) bool bFound = false; for( size_t n = 0; n < aLinkTbl.size(); ) { - tools::SvRef<SvBaseLink>* pTmp = aLinkTbl[ n ]; - if( pLink == *pTmp ) + tools::SvRef<SvBaseLink>& rTmp = aLinkTbl[ n ]; + if( pLink == rTmp.get() ) { - (*pTmp)->Disconnect(); - (*pTmp)->SetLinkManager( NULL ); - (*pTmp).Clear(); + rTmp->Disconnect(); + rTmp->SetLinkManager( NULL ); + rTmp.Clear(); bFound = true; } // Remove empty ones if they exist - if( !pTmp->Is() ) + if( !rTmp.Is() ) { - delete pTmp; aLinkTbl.erase( aLinkTbl.begin() + n ); if( bFound ) return ; @@ -143,13 +141,12 @@ void LinkManager::Remove( size_t nPos, size_t nCnt ) for( size_t n = nPos; n < nPos + nCnt; ++n) { - tools::SvRef<SvBaseLink>* pTmp = aLinkTbl[ n ]; - if( pTmp->Is() ) + tools::SvRef<SvBaseLink>& rTmp = aLinkTbl[ n ]; + if( rTmp.Is() ) { - (*pTmp)->Disconnect(); - (*pTmp)->SetLinkManager( NULL ); + rTmp->Disconnect(); + rTmp->SetLinkManager( NULL ); } - delete pTmp; } aLinkTbl.erase( aLinkTbl.begin() + nPos, aLinkTbl.begin() + nPos + nCnt ); } @@ -160,19 +157,17 @@ bool LinkManager::Insert( SvBaseLink* pLink ) { for( size_t n = 0; n < aLinkTbl.size(); ++n ) { - tools::SvRef<SvBaseLink>* pTmp = aLinkTbl[ n ]; - if( !pTmp->Is() ) + tools::SvRef<SvBaseLink>& rTmp = aLinkTbl[ n ]; + if( !rTmp.Is() ) { - delete pTmp; aLinkTbl.erase( aLinkTbl.begin() + n-- ); } - else if( pLink == *pTmp ) + else if( pLink == rTmp.get() ) return false; // No duplicate links inserted } - tools::SvRef<SvBaseLink>* pTmp = new tools::SvRef<SvBaseLink>( pLink ); pLink->SetLinkManager( this ); - aLinkTbl.push_back( pTmp ); + aLinkTbl.push_back( tools::SvRef<SvBaseLink>(pLink) ); return true; } @@ -295,13 +290,13 @@ void LinkManager::UpdateAllLinks( std::vector<SvBaseLink*> aTmpArr; for( size_t n = 0; n < aLinkTbl.size(); ++n ) { - SvBaseLink* pLink = *aLinkTbl[ n ]; - if( !pLink ) + tools::SvRef<SvBaseLink>& rLink = aLinkTbl[ n ]; + if( !rLink.Is() ) { Remove( n-- ); continue; } - aTmpArr.push_back( pLink ); + aTmpArr.push_back( rLink.get() ); } for( size_t n = 0; n < aTmpArr.size(); ++n ) @@ -311,7 +306,7 @@ void LinkManager::UpdateAllLinks( // search first in the array after the entry bool bFound = false; for( size_t i = 0; i < aLinkTbl.size(); ++i ) - if( pLink == *aLinkTbl[ i ] ) + if( pLink == aLinkTbl[ i ].get() ) { bFound = true; break; @@ -419,7 +414,7 @@ void LinkManager::ReconnectDdeLink(SfxObjectShell& rServer) for (size_t i = 0; i < n; ++i) { - ::sfx2::SvBaseLink* p = *rLinks[i]; + ::sfx2::SvBaseLink* p = rLinks[i].get(); OUString aType, aFile, aLink, aFilter; if (!GetDisplayNames(p, &aType, &aFile, &aLink, &aFilter)) continue; |