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>
This commit is contained in:
Mike Kaganski 2021-04-02 15:12:00 +03:00
parent 711ec7b6c7
commit 86d298f87f
9 changed files with 50 additions and 84 deletions

View file

@ -46,20 +46,17 @@ DlgEdFactory::~DlgEdFactory() COVERITY_NOEXCEPT_FALSE
IMPL_LINK( DlgEdFactory, MakeObject, SdrObjCreatorParams, aParams, SdrObject* )
{
static bool bNeedsInit = true;
static uno::Reference< lang::XMultiServiceFactory > xDialogSFact;
if( bNeedsInit )
{
static const uno::Reference<lang::XMultiServiceFactory> xDialogSFact = [] {
uno::Reference<lang::XMultiServiceFactory> xFact;
uno::Reference< uno::XComponentContext> xContext = ::comphelper::getProcessComponentContext();
uno::Reference< container::XNameContainer > xC( xContext->getServiceManager()->createInstanceWithContext( "com.sun.star.awt.UnoControlDialogModel", xContext ), uno::UNO_QUERY );
if( xC.is() )
{
uno::Reference< lang::XMultiServiceFactory > xModFact( xC, uno::UNO_QUERY );
xDialogSFact = xModFact;
xFact = xModFact;
}
bNeedsInit = false;
}
return xFact;
}();
SdrObject* pNewObj = nullptr;
if( (aParams.nInventor == SdrInventor::BasicDialog) &&

View file

@ -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() )

View file

@ -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;
}

View file

@ -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 );
}

View file

@ -214,10 +214,8 @@ bool isAllowlistedLanguage(const OUString& lang)
(void) lang;
return true;
#else
static bool bInitialized = false;
static std::vector<OUString> aAllowlist;
if (!bInitialized)
{
static const std::vector<OUString> aAllowlist = [] {
std::vector<OUString> aList;
// coverity[tainted_data] - we trust the contents of this variable
const char* pAllowlist = getenv("LOK_ALLOWLIST_LANGUAGES");
if (pAllowlist)
@ -231,16 +229,16 @@ bool isAllowlistedLanguage(const OUString& lang)
continue;
std::cerr << s << " ";
aAllowlist.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8));
aList.emplace_back(OStringToOUString(s.c_str(), RTL_TEXTENCODING_UTF8));
}
std::cerr << std::endl;
}
if (aAllowlist.empty())
if (aList.empty())
std::cerr << "No language allowlisted, turning off the language support." << std::endl;
bInitialized = true;
}
return aList;
}();
if (aAllowlist.empty())
return false;

View file

@ -533,8 +533,6 @@ OOperand* OPredicateCompiler::execute_Operand(OSQLParseNode const * pPredicateNo
bool OPredicateInterpreter::evaluate(OCodeList& rCodeList)
{
static bool bResult;
if (!(rCodeList[0]))
return true; // no Predicate
@ -553,7 +551,7 @@ bool OPredicateInterpreter::evaluate(OCodeList& rCodeList)
DBG_ASSERT(m_aStack.empty(), "Stack error");
DBG_ASSERT(pOperand, "Stack error");
bResult = pOperand->isValid();
const bool bResult = pOperand->isValid();
if (typeid(OOperandResult) == typeid(*pOperand))
delete pOperand;
return bResult;

View file

@ -200,15 +200,7 @@ void CrashReporter::updateMinidumpLocation()
bool CrashReporter::crashReportInfoExists()
{
static bool first = true;
static bool InfoExist = false;
if (first)
{
first = false;
InfoExist = crashreport::readConfig(CrashReporter::getIniFileName(), nullptr);
}
static const bool InfoExist = crashreport::readConfig(CrashReporter::getIniFileName(), nullptr);
return InfoExist;
}

View file

@ -51,18 +51,16 @@ using namespace com::sun::star;
static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
{
static SfxItemPropertyMapEntry aHdFtPropertyMap_Impl[] =
{
SVX_UNOEDIT_CHAR_PROPERTIES,
SVX_UNOEDIT_FONT_PROPERTIES,
SVX_UNOEDIT_PARA_PROPERTIES,
SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
{ u"", 0, css::uno::Type(), 0, 0 }
};
static bool bTwipsSet = false;
static const SvxItemPropertySet aHdFtPropertySet_Impl = [] {
SfxItemPropertyMapEntry aHdFtPropertyMap_Impl[] =
{
SVX_UNOEDIT_CHAR_PROPERTIES,
SVX_UNOEDIT_FONT_PROPERTIES,
SVX_UNOEDIT_PARA_PROPERTIES,
SVX_UNOEDIT_NUMBERING_PROPERTIE, // for completeness of service ParagraphProperties
{ u"", 0, css::uno::Type(), 0, 0 }
};
if (!bTwipsSet)
{
// modify PropertyMap to include CONVERT_TWIPS flag for font height
// (headers/footers are in twips)
@ -79,9 +77,9 @@ static const SvxItemPropertySet * lcl_GetHdFtPropertySet()
++pEntry;
}
bTwipsSet = true;
}
static SvxItemPropertySet aHdFtPropertySet_Impl( aHdFtPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool() );
return SvxItemPropertySet(aHdFtPropertyMap_Impl, SdrObject::GetGlobalDrawObjectItemPool());
}();
return &aHdFtPropertySet_Impl;
}

View file

@ -147,30 +147,28 @@ extern "C" bool GetSpecialCharsForEdit(weld::Widget* i_pParent, const vcl::Font&
static OUString SfxGetSpecialCharsForEdit(weld::Widget* pParent, const vcl::Font& rFont)
{
static bool bDetermineFunction = false;
static PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = nullptr;
SolarMutexGuard aGuard;
if ( !bDetermineFunction )
{
bDetermineFunction = true;
static const PFunc_getSpecialCharsForEdit pfunc_getSpecialCharsForEdit = [] {
PFunc_getSpecialCharsForEdit pfunc = nullptr;
#ifndef DISABLE_DYNLOADING
osl::Module aMod;
aMod.loadRelative(&thisModule, SVLIBRARY("cui"));
// get symbol
pfunc_getSpecialCharsForEdit = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit"));
DBG_ASSERT( pfunc_getSpecialCharsForEdit, "GetSpecialCharsForEdit() not found!" );
pfunc = reinterpret_cast<PFunc_getSpecialCharsForEdit>(aMod.getFunctionSymbol("GetSpecialCharsForEdit"));
DBG_ASSERT( pfunc, "GetSpecialCharsForEdit() not found!" );
aMod.release();
#else
pfunc_getSpecialCharsForEdit = GetSpecialCharsForEdit;
pfunc = GetSpecialCharsForEdit;
#endif
}
return pfunc;
}();
OUString aRet;
if ( pfunc_getSpecialCharsForEdit )
{
SolarMutexGuard aGuard;
(*pfunc_getSpecialCharsForEdit)( pParent, rFont, aRet );
}
return aRet;
}