diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2021-04-02 15:12:00 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2021-04-02 17:22:21 +0200 |
commit | 86d298f87f00fe70d31a65b7e98f9b17fa80cb6b (patch) | |
tree | 0b7a389105ead641d092e56ff6fb1d49180f6265 /basic | |
parent | 711ec7b6c71410b850cdf6d1411d054ca34ec5a0 (diff) |
Simplify some static variable initializations
Change-Id: I6cdd44aa66b9597ccc51fc3fd69b57485ccb3230
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/113515
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'basic')
-rw-r--r-- | basic/source/classes/sbunoobj.cxx | 14 | ||||
-rw-r--r-- | basic/source/runtime/iosys.cxx | 14 | ||||
-rw-r--r-- | basic/source/runtime/methods1.cxx | 17 |
3 files changed, 15 insertions, 30 deletions
diff --git a/basic/source/classes/sbunoobj.cxx b/basic/source/classes/sbunoobj.cxx index 9f00a8f231c9..fcd491462528 100644 --- a/basic/source/classes/sbunoobj.cxx +++ b/basic/source/classes/sbunoobj.cxx @@ -233,22 +233,18 @@ static Reference< XTypeConverter > const & getTypeConverter_Impl() // #111851 factory function to create an OLE object SbUnoObject* createOLEObject_Impl( const OUString& aType ) { - static Reference< XMultiServiceFactory > xOLEFactory; - static bool bNeedsInit = true; - - if( bNeedsInit ) - { - bNeedsInit = false; - + static const Reference<XMultiServiceFactory> xOLEFactory = [] { + Reference<XMultiServiceFactory> xFactory; Reference< XComponentContext > xContext( comphelper::getProcessComponentContext() ); if( xContext.is() ) { Reference<XMultiComponentFactory> xSMgr = xContext->getServiceManager(); - xOLEFactory.set( + xFactory.set( xSMgr->createInstanceWithContext( "com.sun.star.bridge.OleObjectFactory", xContext ), UNO_QUERY ); } - } + return xFactory; + }(); SbUnoObject* pUnoObj = nullptr; if( xOLEFactory.is() ) diff --git a/basic/source/runtime/iosys.cxx b/basic/source/runtime/iosys.cxx index 4c991c6676c7..0cf83c509a39 100644 --- a/basic/source/runtime/iosys.cxx +++ b/basic/source/runtime/iosys.cxx @@ -133,17 +133,12 @@ void SbiStream::MapError() // #89378 New semantic: Don't just ask for UNO but for UCB bool hasUno() { - static bool bNeedInit = true; - static bool bRetVal = true; - - if( bNeedInit ) - { - bNeedInit = false; + static const bool bRetVal = [] { Reference< XComponentContext > xContext = comphelper::getProcessComponentContext(); if( !xContext.is() ) { // No service manager at all - bRetVal = false; + return false; } else { @@ -152,10 +147,11 @@ bool hasUno() if ( !( xManager->queryContentProvider( "file:///" ).is() ) ) { // No UCB - bRetVal = false; + return false; } } - } + return true; + }(); return bRetVal; } diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 2f89a90a8149..9addf7140adf 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -71,23 +71,16 @@ static Reference< XCalendar4 > const & getLocaleCalendar() { static Reference< XCalendar4 > xCalendar = LocaleCalendar2::create(getProcessComponentContext()); static css::lang::Locale aLastLocale; - static bool bNeedsInit = true; + static bool bNeedsReload = true; css::lang::Locale aLocale = Application::GetSettings().GetLanguageTag().getLocale(); - bool bNeedsReload = false; - if( bNeedsInit ) - { - bNeedsInit = false; - bNeedsReload = true; - } - else if( aLocale.Language != aLastLocale.Language || + bNeedsReload = bNeedsReload || + ( aLocale.Language != aLastLocale.Language || aLocale.Country != aLastLocale.Country || - aLocale.Variant != aLastLocale.Variant ) - { - bNeedsReload = true; - } + aLocale.Variant != aLastLocale.Variant ); if( bNeedsReload ) { + bNeedsReload = false; aLastLocale = aLocale; xCalendar->loadDefaultCalendar( aLocale ); } |