Kaydet (Commit) d69795b9 authored tarafından Jochen Nitschke's avatar Jochen Nitschke Kaydeden (comit) Noel Grandin

use local statics in getTypes functions

... instead of double checked locking patterns.

Change-Id: I1b86ce723ff22dd357b3ed69a52757b085472424
Reviewed-on: https://gerrit.libreoffice.org/38906Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 76ed00f8
...@@ -3130,21 +3130,13 @@ void SfxLibrary::removeByName( const OUString& Name ) ...@@ -3130,21 +3130,13 @@ void SfxLibrary::removeByName( const OUString& Name )
// XTypeProvider // XTypeProvider
Sequence< Type > SfxLibrary::getTypes() Sequence< Type > SfxLibrary::getTypes()
{ {
static OTypeCollection * s_pTypes_NameContainer = nullptr; static OTypeCollection ourTypes_NameContainer(
if( !s_pTypes_NameContainer )
{
MutexGuard aGuard( Mutex::getGlobalMutex() );
if( !s_pTypes_NameContainer )
{
static OTypeCollection s_aTypes_NameContainer(
cppu::UnoType<XNameContainer>::get(), cppu::UnoType<XNameContainer>::get(),
cppu::UnoType<XContainer>::get(), cppu::UnoType<XContainer>::get(),
cppu::UnoType<XChangesNotifier>::get(), cppu::UnoType<XChangesNotifier>::get(),
OComponentHelper::getTypes() ); OComponentHelper::getTypes() );
s_pTypes_NameContainer = &s_aTypes_NameContainer;
} return ourTypes_NameContainer.getTypes();
}
return s_pTypes_NameContainer->getTypes();
} }
......
...@@ -27,7 +27,6 @@ ...@@ -27,7 +27,6 @@
#include <cppuhelper/weakref.hxx> #include <cppuhelper/weakref.hxx>
#include <editeng/unopracc.hxx> #include <editeng/unopracc.hxx>
#include <editeng/unoedsrc.hxx> #include <editeng/unoedsrc.hxx>
#include <osl/mutex.hxx>
using namespace ::com::sun::star; using namespace ::com::sun::star;
...@@ -67,30 +66,14 @@ void SAL_CALL SvxAccessibleTextPropertySet::release() ...@@ -67,30 +66,14 @@ void SAL_CALL SvxAccessibleTextPropertySet::release()
// XTypeProvider // XTypeProvider
uno::Sequence< uno::Type > SAL_CALL SvxAccessibleTextPropertySet::getTypes() uno::Sequence< uno::Type > SAL_CALL SvxAccessibleTextPropertySet::getTypes()
{ {
static ::cppu::OTypeCollection* pTypeCollection = nullptr ; static ::cppu::OTypeCollection ourTypeCollection(
// double-checked locking pattern.
if ( pTypeCollection == nullptr )
{
osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() ) ;
// Control these pointer again ... it can be, that another instance will be faster then these!
if ( pTypeCollection == nullptr )
{
// Create a static typecollection ...
static ::cppu::OTypeCollection aTypeCollection(
::cppu::UnoType<beans::XPropertySet>::get(), ::cppu::UnoType<beans::XPropertySet>::get(),
::cppu::UnoType<beans::XMultiPropertySet>::get(), ::cppu::UnoType<beans::XMultiPropertySet>::get(),
::cppu::UnoType<beans::XPropertyState>::get(), ::cppu::UnoType<beans::XPropertyState>::get(),
::cppu::UnoType<lang::XServiceInfo>::get(), ::cppu::UnoType<lang::XServiceInfo>::get(),
::cppu::UnoType<lang::XTypeProvider>::get() ); ::cppu::UnoType<lang::XTypeProvider>::get() );
// ... and set his address to static pointer! return ourTypeCollection.getTypes() ;
pTypeCollection = &aTypeCollection ;
}
}
return pTypeCollection->getTypes() ;
} }
uno::Sequence< sal_Int8 > SAL_CALL SvxAccessibleTextPropertySet::getImplementationId() uno::Sequence< sal_Int8 > SAL_CALL SvxAccessibleTextPropertySet::getImplementationId()
......
...@@ -137,29 +137,22 @@ XTYPEPROVIDER_COMMON_IMPL( CachedContentResultSetStub ) ...@@ -137,29 +137,22 @@ XTYPEPROVIDER_COMMON_IMPL( CachedContentResultSetStub )
Sequence< Type > SAL_CALL CachedContentResultSetStub Sequence< Type > SAL_CALL CachedContentResultSetStub
::getTypes() ::getTypes()
{ {
static Sequence< Type >* pTypes = nullptr; static Sequence<Type> ourTypes(
if( !pTypes ) { CPPU_TYPE_REF( XTypeProvider ),
{ CPPU_TYPE_REF( XServiceInfo ),
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() ); CPPU_TYPE_REF( XComponent ),
if( !pTypes ) CPPU_TYPE_REF( XCloseable ),
{ CPPU_TYPE_REF( XResultSetMetaDataSupplier ),
pTypes = new Sequence< Type >(13); CPPU_TYPE_REF( XPropertySet ),
(*pTypes)[0] = CPPU_TYPE_REF( XTypeProvider ); CPPU_TYPE_REF( XPropertyChangeListener ),
(*pTypes)[1] = CPPU_TYPE_REF( XServiceInfo ); CPPU_TYPE_REF( XVetoableChangeListener ),
(*pTypes)[2] = CPPU_TYPE_REF( XComponent ); CPPU_TYPE_REF( XResultSet ),
(*pTypes)[3] = CPPU_TYPE_REF( XCloseable ); CPPU_TYPE_REF( XContentAccess ),
(*pTypes)[4] = CPPU_TYPE_REF( XResultSetMetaDataSupplier ); CPPU_TYPE_REF( XRow ),
(*pTypes)[5] = CPPU_TYPE_REF( XPropertySet ); CPPU_TYPE_REF( XFetchProvider ),
(*pTypes)[6] = CPPU_TYPE_REF( XPropertyChangeListener ); CPPU_TYPE_REF( XFetchProviderForContentAccess ) } );
(*pTypes)[7] = CPPU_TYPE_REF( XVetoableChangeListener );
(*pTypes)[8] = CPPU_TYPE_REF( XResultSet ); return ourTypes;
(*pTypes)[9] = CPPU_TYPE_REF( XContentAccess );
(*pTypes)[10] = CPPU_TYPE_REF( XRow );
(*pTypes)[11] = CPPU_TYPE_REF( XFetchProvider );
(*pTypes)[12] = CPPU_TYPE_REF( XFetchProviderForContentAccess );
}
}
return *pTypes;
} }
......
...@@ -74,20 +74,11 @@ throw () ...@@ -74,20 +74,11 @@ throw ()
css::uno::Sequence< css::uno::Type > SAL_CALL OTempFileService::getTypes( ) css::uno::Sequence< css::uno::Type > SAL_CALL OTempFileService::getTypes( )
{ {
static ::cppu::OTypeCollection* pTypeCollection = nullptr; static ::cppu::OTypeCollection ourTypeCollection(
if ( pTypeCollection == nullptr )
{
::osl::MutexGuard aGuard( ::osl::Mutex::getGlobalMutex() );
if ( pTypeCollection == nullptr )
{
static ::cppu::OTypeCollection aTypeCollection(
cppu::UnoType<css::beans::XPropertySet>::get() cppu::UnoType<css::beans::XPropertySet>::get()
,OTempFileBase::getTypes() ); ,OTempFileBase::getTypes() );
pTypeCollection = &aTypeCollection;
} return ourTypeCollection.getTypes();
}
return pTypeCollection->getTypes();
}; };
// XTempFile // XTempFile
......
...@@ -83,15 +83,8 @@ XTYPEPROVIDER_COMMON_IMPL( Content ); ...@@ -83,15 +83,8 @@ XTYPEPROVIDER_COMMON_IMPL( Content );
// virtual // virtual
uno::Sequence< uno::Type > SAL_CALL Content::getTypes() uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
{ {
static cppu::OTypeCollection* pCollection = nullptr; static cppu::OTypeCollection ourTypeCollection(
CPPU_TYPE_REF( lang::XTypeProvider ),
if ( !pCollection )
{
osl::MutexGuard aGuard( osl::Mutex::getGlobalMutex() );
if ( !pCollection )
{
static cppu::OTypeCollection aCollection(
CPPU_TYPE_REF( lang::XTypeProvider ),
CPPU_TYPE_REF( lang::XServiceInfo ), CPPU_TYPE_REF( lang::XServiceInfo ),
CPPU_TYPE_REF( lang::XComponent ), CPPU_TYPE_REF( lang::XComponent ),
CPPU_TYPE_REF( ucb::XContent ), CPPU_TYPE_REF( ucb::XContent ),
...@@ -101,11 +94,8 @@ uno::Sequence< uno::Type > SAL_CALL Content::getTypes() ...@@ -101,11 +94,8 @@ uno::Sequence< uno::Type > SAL_CALL Content::getTypes()
CPPU_TYPE_REF( beans::XPropertyContainer ), CPPU_TYPE_REF( beans::XPropertyContainer ),
CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ), CPPU_TYPE_REF( beans::XPropertySetInfoChangeNotifier ),
CPPU_TYPE_REF( container::XChild ) ); CPPU_TYPE_REF( container::XChild ) );
pCollection = &aCollection;
}
}
return (*pCollection).getTypes(); return ourTypeCollection.getTypes();
} }
// XServiceInfo methods. // XServiceInfo methods.
......
...@@ -90,23 +90,15 @@ css::uno::Sequence< sal_Int8 > SAL_CALL ContentProvider::getImplementationId() ...@@ -90,23 +90,15 @@ css::uno::Sequence< sal_Int8 > SAL_CALL ContentProvider::getImplementationId()
css::uno::Sequence< css::uno::Type > SAL_CALL ContentProvider::getTypes() css::uno::Sequence< css::uno::Type > SAL_CALL ContentProvider::getTypes()
{ {
static cppu::OTypeCollection* pCollection = nullptr; static cppu::OTypeCollection ourTypeCollection(
if ( !pCollection )
{
osl::Guard< osl::Mutex > aGuard( osl::Mutex::getGlobalMutex() );
if ( !pCollection )
{
static cppu::OTypeCollection collection(
cppu::UnoType<lang::XTypeProvider>::get(), cppu::UnoType<lang::XTypeProvider>::get(),
cppu::UnoType<lang::XServiceInfo>::get(), cppu::UnoType<lang::XServiceInfo>::get(),
cppu::UnoType<ucb::XContentProvider>::get(), cppu::UnoType<ucb::XContentProvider>::get(),
cppu::UnoType<lang::XComponent>::get(), cppu::UnoType<lang::XComponent>::get(),
cppu::UnoType<container::XContainerListener>::get() cppu::UnoType<container::XContainerListener>::get()
); );
pCollection = &collection;
} return ourTypeCollection.getTypes();
}
return (*pCollection).getTypes();
} }
......
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