Kaydet (Commit) 21525441 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:useuniqueptr in comphelper,cppu,registry

Change-Id: Ib353d901827e417498fe4f8e397f1a57c61a9736
Reviewed-on: https://gerrit.libreoffice.org/47794Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 7d8e9444
...@@ -58,12 +58,6 @@ OInstanceLocker::~OInstanceLocker() ...@@ -58,12 +58,6 @@ OInstanceLocker::~OInstanceLocker()
catch ( uno::RuntimeException& ) catch ( uno::RuntimeException& )
{} {}
} }
if ( m_pListenersContainer )
{
delete m_pListenersContainer;
m_pListenersContainer = nullptr;
}
} }
// XComponent // XComponent
...@@ -96,7 +90,7 @@ void SAL_CALL OInstanceLocker::addEventListener( const uno::Reference< lang::XEv ...@@ -96,7 +90,7 @@ void SAL_CALL OInstanceLocker::addEventListener( const uno::Reference< lang::XEv
throw lang::DisposedException(); // TODO throw lang::DisposedException(); // TODO
if ( !m_pListenersContainer ) if ( !m_pListenersContainer )
m_pListenersContainer = new ::comphelper::OInterfaceContainerHelper2( m_aMutex ); m_pListenersContainer.reset( new ::comphelper::OInterfaceContainerHelper2( m_aMutex ) );
m_pListenersContainer->addInterface( xListener ); m_pListenersContainer->addInterface( xListener );
} }
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <cppuhelper/implbase.hxx> #include <cppuhelper/implbase.hxx>
#include <comphelper/interfacecontainer2.hxx> #include <comphelper/interfacecontainer2.hxx>
#include <rtl/ref.hxx> #include <rtl/ref.hxx>
#include <memory>
class OLockListener; class OLockListener;
...@@ -47,7 +48,7 @@ class OInstanceLocker : public ::cppu::WeakImplHelper< css::lang::XComponent, ...@@ -47,7 +48,7 @@ class OInstanceLocker : public ::cppu::WeakImplHelper< css::lang::XComponent,
rtl::Reference< OLockListener > m_xLockListener; rtl::Reference< OLockListener > m_xLockListener;
::comphelper::OInterfaceContainerHelper2* m_pListenersContainer; // list of listeners std::unique_ptr<::comphelper::OInterfaceContainerHelper2> m_pListenersContainer; // list of listeners
bool m_bDisposed; bool m_bDisposed;
bool m_bInitialized; bool m_bInitialized;
......
...@@ -173,11 +173,11 @@ struct TypeDescriptor_Init_Impl ...@@ -173,11 +173,11 @@ struct TypeDescriptor_Init_Impl
{ {
//sal_Bool bDesctructorCalled; //sal_Bool bDesctructorCalled;
// all type description references // all type description references
WeakMap_Impl * pWeakMap; std::unique_ptr<WeakMap_Impl> pWeakMap;
// all type description callbacks // all type description callbacks
std::unique_ptr<CallbackSet_Impl> pCallbacks; std::unique_ptr<CallbackSet_Impl> pCallbacks;
// A cache to hold descriptions // A cache to hold descriptions
TypeDescriptionList_Impl * pCache; std::unique_ptr<TypeDescriptionList_Impl> pCache;
// The mutex to guard all type library accesses // The mutex to guard all type library accesses
std::unique_ptr<Mutex> pMutex; std::unique_ptr<Mutex> pMutex;
...@@ -253,8 +253,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() ...@@ -253,8 +253,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
typelib_typedescription_release( *aIt ); typelib_typedescription_release( *aIt );
++aIt; ++aIt;
} }
delete pCache;
pCache = nullptr;
} }
if( pWeakMap ) if( pWeakMap )
...@@ -304,8 +302,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl() ...@@ -304,8 +302,6 @@ TypeDescriptor_Init_Impl::~TypeDescriptor_Init_Impl()
++aIt; ++aIt;
} }
#endif #endif
delete pWeakMap;
pWeakMap = nullptr;
} }
#if OSL_DEBUG_LEVEL > 0 #if OSL_DEBUG_LEVEL > 0
SAL_INFO_IF( nTypeDescriptionCount, "cppu.typelib", "nTypeDescriptionCount is not zero" ); SAL_INFO_IF( nTypeDescriptionCount, "cppu.typelib", "nTypeDescriptionCount is not zero" );
...@@ -504,7 +500,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) { ...@@ -504,7 +500,7 @@ bool complete(typelib_TypeDescription ** ppTypeDescr, bool initTables) {
// insert into the chache // insert into the chache
MutexGuard aGuard( rInit.getMutex() ); MutexGuard aGuard( rInit.getMutex() );
if( !rInit.pCache ) if( !rInit.pCache )
rInit.pCache = new TypeDescriptionList_Impl; rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
{ {
typelib_typedescription_release( rInit.pCache->front() ); typelib_typedescription_release( rInit.pCache->front() );
...@@ -1560,7 +1556,7 @@ extern "C" void SAL_CALL typelib_typedescription_register( ...@@ -1560,7 +1556,7 @@ extern "C" void SAL_CALL typelib_typedescription_register(
{ {
pTDR = reinterpret_cast<typelib_TypeDescriptionReference *>(*ppNewDescription); pTDR = reinterpret_cast<typelib_TypeDescriptionReference *>(*ppNewDescription);
if( !rInit.pWeakMap ) if( !rInit.pWeakMap )
rInit.pWeakMap = new WeakMap_Impl; rInit.pWeakMap.reset( new WeakMap_Impl );
// description is the weak itself, so register it // description is the weak itself, so register it
(*rInit.pWeakMap)[pTDR->pTypeName->buffer] = pTDR; (*rInit.pWeakMap)[pTDR->pTypeName->buffer] = pTDR;
...@@ -2001,7 +1997,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName( ...@@ -2001,7 +1997,7 @@ extern "C" void SAL_CALL typelib_typedescription_getByName(
// insert into the chache // insert into the chache
MutexGuard aGuard( rInit.getMutex() ); MutexGuard aGuard( rInit.getMutex() );
if( !rInit.pCache ) if( !rInit.pCache )
rInit.pCache = new TypeDescriptionList_Impl; rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
{ {
typelib_typedescription_release( rInit.pCache->front() ); typelib_typedescription_release( rInit.pCache->front() );
...@@ -2059,7 +2055,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( ...@@ -2059,7 +2055,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
// insert into the chache // insert into the chache
MutexGuard aGuard( rInit.getMutex() ); MutexGuard aGuard( rInit.getMutex() );
if( !rInit.pCache ) if( !rInit.pCache )
rInit.pCache = new TypeDescriptionList_Impl; rInit.pCache.reset( new TypeDescriptionList_Impl );
if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize ) if( static_cast<sal_Int32>(rInit.pCache->size()) >= nCacheSize )
{ {
typelib_typedescription_release( rInit.pCache->front() ); typelib_typedescription_release( rInit.pCache->front() );
...@@ -2112,7 +2108,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new( ...@@ -2112,7 +2108,7 @@ extern "C" void SAL_CALL typelib_typedescriptionreference_new(
} }
if( !rInit.pWeakMap ) if( !rInit.pWeakMap )
rInit.pWeakMap = new WeakMap_Impl; rInit.pWeakMap.reset( new WeakMap_Impl );
// Heavy hack, the const sal_Unicode * is hold by the typedescription reference // Heavy hack, the const sal_Unicode * is hold by the typedescription reference
// not registered // not registered
rInit.pWeakMap->operator[]( (*ppTDR)->pTypeName->buffer ) = *ppTDR; rInit.pWeakMap->operator[]( (*ppTDR)->pTypeName->buffer ) = *ppTDR;
......
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
#include <cstring> #include <cstring>
#include <memory> #include <memory>
#include <new> #include <new>
#include <vector>
#include <string.h> #include <string.h>
#include <sal/types.h> #include <sal/types.h>
...@@ -185,60 +186,38 @@ BlopObject::~BlopObject() ...@@ -185,60 +186,38 @@ BlopObject::~BlopObject()
class StringCache class StringCache
{ {
public: public:
sal_Unicode** m_stringTable; std::vector<std::unique_ptr<sal_Unicode[]>> m_stringTable;
sal_uInt16 m_numOfStrings;
sal_uInt16 m_stringsCopied; sal_uInt16 m_stringsCopied;
explicit StringCache(sal_uInt16 size); // throws std::bad_alloc explicit StringCache(sal_uInt16 size); // throws std::bad_alloc
~StringCache();
const sal_Unicode* getString(sal_uInt16 index) const; const sal_Unicode* getString(sal_uInt16 index) const;
sal_uInt16 createString(const sal_uInt8* buffer); // throws std::bad_alloc sal_uInt16 createString(const sal_uInt8* buffer); // throws std::bad_alloc
}; };
StringCache::StringCache(sal_uInt16 size) StringCache::StringCache(sal_uInt16 size)
: m_stringTable(nullptr) : m_stringTable(size)
, m_numOfStrings(size)
, m_stringsCopied(0) , m_stringsCopied(0)
{ {
m_stringTable = new sal_Unicode*[m_numOfStrings];
for (sal_uInt16 i = 0; i < m_numOfStrings; i++)
{
m_stringTable[i] = nullptr;
}
}
StringCache::~StringCache()
{
if (m_stringTable)
{
for (sal_uInt16 i = 0; i < m_stringsCopied; i++)
{
delete[] m_stringTable[i];
}
delete[] m_stringTable;
}
} }
const sal_Unicode* StringCache::getString(sal_uInt16 index) const const sal_Unicode* StringCache::getString(sal_uInt16 index) const
{ {
if ((index > 0) && (index <= m_stringsCopied)) if ((index > 0) && (index <= m_stringsCopied))
return m_stringTable[index - 1]; return m_stringTable[index - 1].get();
else else
return nullptr; return nullptr;
} }
sal_uInt16 StringCache::createString(const sal_uInt8* buffer) sal_uInt16 StringCache::createString(const sal_uInt8* buffer)
{ {
if (m_stringsCopied < m_numOfStrings) if (m_stringsCopied < m_stringTable.size())
{ {
sal_uInt32 len = UINT16StringLen(buffer); sal_uInt32 len = UINT16StringLen(buffer);
m_stringTable[m_stringsCopied] = new sal_Unicode[len + 1]; m_stringTable[m_stringsCopied].reset( new sal_Unicode[len + 1] );
readString(buffer, m_stringTable[m_stringsCopied], (len + 1) * sizeof(sal_Unicode)); readString(buffer, m_stringTable[m_stringsCopied].get(), (len + 1) * sizeof(sal_Unicode));
return ++m_stringsCopied; return ++m_stringsCopied;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment