summaryrefslogtreecommitdiff
path: root/cppuhelper
diff options
context:
space:
mode:
authorNoel Grandin <noel.grandin@collabora.co.uk>2018-09-28 10:16:39 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2018-10-01 08:16:57 +0200
commit39f563ca59cd70a208c5fbc81e40bbe51d689ee4 (patch)
tree468a4f284a7ddced6d3cac81b9cf965060f1cb09 /cppuhelper
parent52d0aca586f3754cfab997387a9fb11fe9f63fc8 (diff)
loplugin:useuniqueptr in ComponentContext
no need to store such small movable and ref-counted objects separately Change-Id: Idf4262a8edbfe07fcb4b96d1025924224b72b5b6 Reviewed-on: https://gerrit.libreoffice.org/61113 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'cppuhelper')
-rw-r--r--cppuhelper/source/component_context.cxx73
1 files changed, 29 insertions, 44 deletions
diff --git a/cppuhelper/source/component_context.cxx b/cppuhelper/source/component_context.cxx
index 7fc86360c692..f6b7aa0cf0da 100644
--- a/cppuhelper/source/component_context.cxx
+++ b/cppuhelper/source/component_context.cxx
@@ -137,7 +137,7 @@ protected:
, lateInit( lateInit_ )
{}
};
- typedef std::unordered_map< OUString, ContextEntry * > t_map;
+ typedef std::unordered_map< OUString, ContextEntry > t_map;
t_map m_map;
Reference< lang::XMultiComponentFactory > m_xSMgr;
@@ -150,7 +150,6 @@ public:
ComponentContext(
ContextEntry_Init const * pEntries, sal_Int32 nEntries,
Reference< XComponentContext > const & xDelegate );
- virtual ~ComponentContext() override;
// XComponentContext
virtual Any SAL_CALL getValueByName( OUString const & rName ) override;
@@ -177,12 +176,11 @@ public:
void ComponentContext::insertByName(
OUString const & name, Any const & element )
{
- t_map::mapped_type entry(
- new ContextEntry(
+ ContextEntry entry(
element,
/* lateInit_: */
name.startsWith( "/singletons/" ) &&
- !element.hasValue() ) );
+ !element.hasValue() );
MutexGuard guard( m_mutex );
std::pair<t_map::iterator, bool> insertion( m_map.emplace(
name, entry ) );
@@ -202,7 +200,6 @@ void ComponentContext::removeByName( OUString const & name )
"no such element: " + name,
static_cast<OWeakObject *>(this) );
- delete iFind->second;
m_map.erase(iFind);
}
@@ -212,7 +209,7 @@ void ComponentContext::replaceByName(
OUString const & name, Any const & element )
{
MutexGuard guard( m_mutex );
- t_map::const_iterator const iFind( m_map.find( name ) );
+ t_map::iterator iFind( m_map.find( name ) );
if (iFind == m_map.end())
throw container::NoSuchElementException(
"no such element: " + name,
@@ -220,13 +217,13 @@ void ComponentContext::replaceByName(
if (name.startsWith( "/singletons/" ) &&
!element.hasValue())
{
- iFind->second->value.clear();
- iFind->second->lateInit = true;
+ iFind->second.value.clear();
+ iFind->second.lateInit = true;
}
else
{
- iFind->second->value = element;
- iFind->second->lateInit = false;
+ iFind->second.value = element;
+ iFind->second.lateInit = false;
}
}
@@ -276,13 +273,13 @@ sal_Bool ComponentContext::hasElements()
Any ComponentContext::lookupMap( OUString const & rName )
{
ResettableMutexGuard guard( m_mutex );
- t_map::const_iterator iFind( m_map.find( rName ) );
+ t_map::iterator iFind( m_map.find( rName ) );
if (iFind == m_map.end())
return Any();
- t_map::mapped_type pEntry = iFind->second;
- if (! pEntry->lateInit)
- return pEntry->value;
+ ContextEntry& rFindEntry = iFind->second;
+ if (! rFindEntry.lateInit)
+ return rFindEntry.value;
// late init singleton entry
Reference< XInterface > xInstance;
@@ -351,14 +348,14 @@ Any ComponentContext::lookupMap( OUString const & rName )
iFind = m_map.find( rName );
if (iFind != m_map.end())
{
- pEntry = iFind->second;
- if (pEntry->lateInit)
+ ContextEntry & rEntry = iFind->second;
+ if (rEntry.lateInit)
{
- pEntry->value <<= xInstance;
- pEntry->lateInit = false;
- return pEntry->value;
+ rEntry.value <<= xInstance;
+ rEntry.lateInit = false;
+ return rEntry.value;
}
- ret = pEntry->value;
+ ret = rEntry.value;
}
guard.clear();
if (ret != xInstance) {
@@ -397,44 +394,35 @@ Reference< lang::XMultiComponentFactory > ComponentContext::getServiceManager()
return m_xSMgr;
}
-ComponentContext::~ComponentContext()
-{
- t_map::const_iterator iPos( m_map.begin() );
- t_map::const_iterator const iEnd( m_map.end() );
- for ( ; iPos != iEnd; ++iPos )
- delete iPos->second;
- m_map.clear();
-}
-
void ComponentContext::disposing()
{
Reference< lang::XComponent > xTDMgr, xAC; // to be disposed separately
// dispose all context objects
- t_map::const_iterator iPos( m_map.begin() );
- t_map::const_iterator const iEnd( m_map.end() );
+ t_map::iterator iPos( m_map.begin() );
+ t_map::iterator const iEnd( m_map.end() );
for ( ; iPos != iEnd; ++iPos )
{
- t_map::mapped_type pEntry = iPos->second;
+ ContextEntry& rEntry = iPos->second;
// service manager disposed separately
if (!m_xSMgr.is() ||
!iPos->first.startsWith( SMGR_SINGLETON ))
{
- if (pEntry->lateInit)
+ if (rEntry.lateInit)
{
// late init
MutexGuard guard( m_mutex );
- if (pEntry->lateInit)
+ if (rEntry.lateInit)
{
- pEntry->value.clear(); // release factory
- pEntry->lateInit = false;
+ rEntry.value.clear(); // release factory
+ rEntry.lateInit = false;
continue;
}
}
Reference< lang::XComponent > xComp;
- pEntry->value >>= xComp;
+ rEntry.value >>= xComp;
if (xComp.is())
{
if ( iPos->first == TDMGR_SINGLETON )
@@ -461,9 +449,6 @@ void ComponentContext::disposing()
// dispose tdmgr; revokes callback from cppu runtime
try_dispose( xTDMgr );
- iPos = m_map.begin();
- for ( ; iPos != iEnd; ++iPos )
- delete iPos->second;
m_map.clear();
// Hack to terminate any JNI bridge's AsynchronousFinalizer thread (as JNI
@@ -503,15 +488,15 @@ ComponentContext::ComponentContext(
if (rEntry.bLateInitService)
{
// singleton entry
- m_map[ rEntry.name ] = new ContextEntry( Any(), true );
+ m_map.emplace( rEntry.name, ContextEntry( Any(), true ) );
// service
- m_map[ rEntry.name + "/service" ] = new ContextEntry( rEntry.value, false );
+ m_map.emplace( rEntry.name + "/service", ContextEntry( rEntry.value, false ) );
// initial-arguments are provided as optional context entry
}
else
{
// only value, no late init factory nor string
- m_map[ rEntry.name ] = new ContextEntry( rEntry.value, false );
+ m_map.emplace( rEntry.name, ContextEntry( rEntry.value, false ) );
}
}