diff options
19 files changed, 114 insertions, 149 deletions
diff --git a/basic/source/comp/basiccharclass.cxx b/basic/source/comp/basiccharclass.cxx index 818190b9fd72..c06bd8bb6047 100644 --- a/basic/source/comp/basiccharclass.cxx +++ b/basic/source/comp/basiccharclass.cxx @@ -34,9 +34,7 @@ bool BasicCharClass::isLetter( sal_Unicode c ) bool BasicCharClass::isLetterUnicode( sal_Unicode c ) { - static CharClass* pCharClass = nullptr; - if( pCharClass == nullptr ) - pCharClass = new CharClass( Application::GetSettings().GetLanguageTag() ); + static CharClass* pCharClass = new CharClass( Application::GetSettings().GetLanguageTag() ); // can we get pCharClass to accept a sal_Unicode instead of this waste? return pCharClass->isLetter( OUString(c), 0 ); } diff --git a/basic/source/runtime/methods.cxx b/basic/source/runtime/methods.cxx index 84202c8d4e45..9490ca242f90 100644 --- a/basic/source/runtime/methods.cxx +++ b/basic/source/runtime/methods.cxx @@ -129,14 +129,7 @@ static long GetDayDiff( const Date& rDate ); static const CharClass& GetCharClass() { - static bool bNeedsInit = true; - static LanguageTag aLanguageTag( LANGUAGE_SYSTEM); - if( bNeedsInit ) - { - bNeedsInit = false; - aLanguageTag = Application::GetSettings().GetLanguageTag(); - } - static CharClass aCharClass( aLanguageTag ); + static CharClass aCharClass( Application::GetSettings().GetLanguageTag() ); return aCharClass; } @@ -169,11 +162,7 @@ OUString getFullPath( const OUString& aRelPath ) // TODO: -> SbiGlobals static uno::Reference< ucb::XSimpleFileAccess3 > const & getFileAccess() { - static uno::Reference< ucb::XSimpleFileAccess3 > xSFI; - if( !xSFI.is() ) - { - xSFI = ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ); - } + static uno::Reference< ucb::XSimpleFileAccess3 > xSFI = ucb::SimpleFileAccess::create( comphelper::getProcessComponentContext() ); return xSFI; } diff --git a/basic/source/runtime/methods1.cxx b/basic/source/runtime/methods1.cxx index 951c416936bc..32824b6f2c61 100644 --- a/basic/source/runtime/methods1.cxx +++ b/basic/source/runtime/methods1.cxx @@ -70,13 +70,7 @@ using namespace com::sun::star::uno; static Reference< XCalendar4 > const & getLocaleCalendar() { - static Reference< XCalendar4 > xCalendar; - if( !xCalendar.is() ) - { - Reference< XComponentContext > xContext = getProcessComponentContext(); - xCalendar = LocaleCalendar2::create(xContext); - } - + static Reference< XCalendar4 > xCalendar = LocaleCalendar2::create(getProcessComponentContext()); static css::lang::Locale aLastLocale; static bool bNeedsInit = true; diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx index c8131460accf..f111c65fdb52 100644 --- a/basic/source/runtime/runtime.cxx +++ b/basic/source/runtime/runtime.cxx @@ -1337,14 +1337,12 @@ void SbiRuntime::StepCompare( SbxOperator eOp ) // I dumbly follow the pattern :-/ if ( bVBAEnabled && ( p1->IsNull() || p2->IsNull() ) ) { - static SbxVariable* pNULL = nullptr; - - if( !pNULL ) - { - pNULL = new SbxVariable; - pNULL->PutNull(); - pNULL->AddFirstRef(); - } + static SbxVariable* pNULL = [&]() { + SbxVariable* p = new SbxVariable; + p->PutNull(); + p->AddFirstRef(); + return p; + }(); PushVar( pNULL ); } else if( p2->Compare( eOp, *p1 ) ) diff --git a/comphelper/source/misc/backupfilehelper.cxx b/comphelper/source/misc/backupfilehelper.cxx index 315fccb1c501..4c7917e96015 100644 --- a/comphelper/source/misc/backupfilehelper.cxx +++ b/comphelper/source/misc/backupfilehelper.cxx @@ -2044,29 +2044,25 @@ namespace comphelper const std::vector< OUString >& BackupFileHelper::getCustomizationDirNames() { - static std::vector< OUString > aDirNames; - - if (aDirNames.empty()) + static std::vector< OUString > aDirNames = { - aDirNames.emplace_back("config"); // UI config stuff - aDirNames.emplace_back("registry"); // most of the registry stuff - aDirNames.emplace_back("psprint"); // not really needed, can be abandoned - aDirNames.emplace_back("store"); // not really needed, can be abandoned - aDirNames.emplace_back("temp"); // not really needed, can be abandoned - aDirNames.emplace_back("pack"); // own backup dir - } + "config", // UI config stuff + "registry", // most of the registry stuff + "psprint", // not really needed, can be abandoned + "store", // not really needed, can be abandoned + "temp", // not really needed, can be abandoned + "pack" // own backup dir + }; return aDirNames; } const std::vector< OUString >& BackupFileHelper::getCustomizationFileNames() { - static std::vector< OUString > aFileNames; - - if (aFileNames.empty()) + static std::vector< OUString > aFileNames = { - aFileNames.emplace_back("registrymodifications.xcu"); // personal registry stuff - } + "registrymodifications.xcu" // personal registry stuff + }; return aFileNames; } diff --git a/comphelper/source/misc/threadpool.cxx b/comphelper/source/misc/threadpool.cxx index e66d1d18f24e..46c144af8dfd 100644 --- a/comphelper/source/misc/threadpool.cxx +++ b/comphelper/source/misc/threadpool.cxx @@ -109,8 +109,7 @@ ThreadPool& ThreadPool::getSharedOptimalPool() sal_Int32 ThreadPool::getPreferredConcurrency() { - static sal_Int32 ThreadCount = 0; - if (ThreadCount == 0) + static sal_Int32 ThreadCount = [&]() { const sal_Int32 nHardThreads = std::max(std::thread::hardware_concurrency(), 1U); sal_Int32 nThreads = nHardThreads; @@ -122,8 +121,8 @@ sal_Int32 ThreadPool::getPreferredConcurrency() } nThreads = std::min(nHardThreads, nThreads); - ThreadCount = std::max<sal_Int32>(nThreads, 1); - } + return std::max<sal_Int32>(nThreads, 1); + }(); return ThreadCount; } diff --git a/configmgr/source/lock.cxx b/configmgr/source/lock.cxx index 9258b35bfeb7..3c0e25d432c5 100644 --- a/configmgr/source/lock.cxx +++ b/configmgr/source/lock.cxx @@ -27,9 +27,7 @@ namespace configmgr { std::shared_ptr<osl::Mutex> const & lock() { - static std::shared_ptr<osl::Mutex> theLock; - if (!theLock.get()) - theLock.reset(new osl::Mutex); + static std::shared_ptr<osl::Mutex> theLock(new osl::Mutex); return theLock; } diff --git a/connectivity/source/drivers/evoab2/EApi.cxx b/connectivity/source/drivers/evoab2/EApi.cxx index 1830cae593af..41bc62c9ab20 100644 --- a/connectivity/source/drivers/evoab2/EApi.cxx +++ b/connectivity/source/drivers/evoab2/EApi.cxx @@ -173,9 +173,7 @@ bool EApiInit() ESourceRegistry *get_e_source_registry() { - static ESourceRegistry *theInstance; - if (!theInstance) - theInstance = e_source_registry_new_sync(nullptr, nullptr); + static ESourceRegistry *theInstance = e_source_registry_new_sync(nullptr, nullptr); return theInstance; } diff --git a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx index ff48493e1f20..004b46245b4d 100644 --- a/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx +++ b/connectivity/source/drivers/evoab2/NDatabaseMetaData.cxx @@ -1017,10 +1017,9 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); Reference< XResultSet > xResultSet = pResultSet; - static ODatabaseMetaDataResultSet::ORows aRows; - - if(aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = []() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow; aRow.reserve(19); aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); @@ -1044,13 +1043,14 @@ Reference< XResultSet > OEvoabDatabaseMetaData::impl_getTypeInfo_throw( ) aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR); aRow[3] = new ORowSetValueDecorator(sal_Int32(65535)); - aRows.push_back(aRow); - } + tmp.push_back(aRow); + return tmp; + }(); pResultSet->setRows(aRows); return xResultSet; } diff --git a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx index 9ef2a59f6e61..f9d5c282a565 100644 --- a/connectivity/source/drivers/firebird/DatabaseMetaData.cxx +++ b/connectivity/source/drivers/firebird/DatabaseMetaData.cxx @@ -805,10 +805,9 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); uno::Reference< XResultSet > xResultSet = pResultSet; - static ODatabaseMetaDataResultSet::ORows aResults; - - if(aResults.empty()) + static ODatabaseMetaDataResultSet::ORows aResults = [&]() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(19); // Common data @@ -838,7 +837,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Varchar aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); @@ -850,7 +849,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Binary (CHAR) // It is distinguished from Text type by its character set @@ -862,7 +861,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() sal_Int16(ColumnSearch::NONE)); // Searchable aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Varbinary (VARCHAR) aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); @@ -882,12 +881,12 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Longvarbinary (SQL_BLOB) // Distinguished from simple blob with a user-defined subtype. aRow[2] = new ORowSetValueDecorator(DataType::LONGVARBINARY); - aResults.push_back(aRow); + tmp.push_back(aRow); // Integer Types common { @@ -902,17 +901,17 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[1] = new ORowSetValueDecorator(OUString("SMALLINT")); aRow[2] = new ORowSetValueDecorator(DataType::SMALLINT); aRow[3] = new ORowSetValueDecorator(sal_Int16(5)); // Prevision - aResults.push_back(aRow); + tmp.push_back(aRow); // Integer (SQL_LONG) aRow[1] = new ORowSetValueDecorator(OUString("INTEGER")); aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); aRow[3] = new ORowSetValueDecorator(sal_Int16(10)); // Precision - aResults.push_back(aRow); + tmp.push_back(aRow); // Bigint (SQL_INT64) aRow[1] = new ORowSetValueDecorator(OUString("BIGINT")); aRow[2] = new ORowSetValueDecorator(DataType::BIGINT); aRow[3] = new ORowSetValueDecorator(sal_Int16(20)); // Precision - aResults.push_back(aRow); + tmp.push_back(aRow); // Decimal Types common { @@ -928,14 +927,14 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Decimal aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); aRow[6] = new ORowSetValueDecorator(); // Create Params // Float (SQL_FLOAT) @@ -944,14 +943,14 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[3] = new ORowSetValueDecorator(sal_Int16(7)); // Precision aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale aRow[15] = new ORowSetValueDecorator(sal_Int16(7)); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // Double (SQL_DOUBLE) aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE PRECISION")); aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); aRow[3] = new ORowSetValueDecorator(sal_Int16(15)); // Precision aRow[14] = new ORowSetValueDecorator(sal_Int16(1)); // Minimum scale aRow[15] = new ORowSetValueDecorator(sal_Int16(15)); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // TODO: no idea whether D_FLOAT corresponds to an sql type @@ -965,7 +964,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // SQL_TYPE_TIME aRow[1] = new ORowSetValueDecorator(OUString("TIME")); @@ -989,7 +988,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // SQL_BLOB aRow[1] = new ORowSetValueDecorator(OUString("BLOB")); @@ -1001,7 +1000,7 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); + tmp.push_back(aRow); // SQL_BOOLEAN aRow[1] = new ORowSetValueDecorator(OUString("BOOLEAN")); @@ -1013,9 +1012,9 @@ uno::Reference< XResultSet > SAL_CALL ODatabaseMetaData::getTypeInfo() aRow[12] = new ORowSetValueDecorator(false); // Autoincrement aRow[14] = ODatabaseMetaDataResultSet::get0Value(); // Minimum scale aRow[15] = ODatabaseMetaDataResultSet::get0Value(); // Max scale - aResults.push_back(aRow); - - } + tmp.push_back(aRow); + return tmp; + }(); pResultSet->setRows(aResults); return xResultSet; } diff --git a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx index a78b7c91575d..ad8982eb21bc 100644 --- a/connectivity/source/drivers/flat/EDatabaseMetaData.cxx +++ b/connectivity/source/drivers/flat/EDatabaseMetaData.cxx @@ -55,9 +55,9 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( ) ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(::connectivity::ODatabaseMetaDataResultSet::eTypeInfo); Reference< XResultSet > xRef = pResult; - static ODatabaseMetaDataResultSet::ORows aRows; - if(aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = [&]() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow; aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); @@ -80,13 +80,13 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( ) aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("VARCHAR")); aRow[2] = new ORowSetValueDecorator(DataType::VARCHAR); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("LONGVARCHAR")); @@ -94,53 +94,55 @@ Reference< XResultSet > OFlatDatabaseMetaData::impl_getTypeInfo_throw( ) aRow[3] = new ORowSetValueDecorator(sal_Int32(65535)); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("DATE")); aRow[2] = new ORowSetValueDecorator(DataType::DATE); aRow[3] = new ORowSetValueDecorator(sal_Int32(10)); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("TIME")); aRow[2] = new ORowSetValueDecorator(DataType::TIME); aRow[3] = new ORowSetValueDecorator(sal_Int32(8)); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); aRow[3] = new ORowSetValueDecorator(sal_Int32(19)); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("BOOL")); aRow[2] = new ORowSetValueDecorator(DataType::BIT); aRow[3] = ODatabaseMetaDataResultSet::get1Value(); aRow[9] = ODatabaseMetaDataResultSet::getBasicValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("DECIMAL")); aRow[2] = new ORowSetValueDecorator(DataType::DECIMAL); aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); aRow[15] = new ORowSetValueDecorator(sal_Int32(15)); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("DOUBLE")); aRow[2] = new ORowSetValueDecorator(DataType::DOUBLE); aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); aRow[15] = ODatabaseMetaDataResultSet::get0Value(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("NUMERIC")); aRow[2] = new ORowSetValueDecorator(DataType::NUMERIC); aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); aRow[15] = new ORowSetValueDecorator(sal_Int32(20)); - aRows.push_back(aRow); - } + tmp.push_back(aRow); + + return tmp; + }(); pResult->setRows(aRows); return xRef; diff --git a/connectivity/source/drivers/hsqldb/HDriver.cxx b/connectivity/source/drivers/hsqldb/HDriver.cxx index 2db53def866a..be2d1040c8dc 100644 --- a/connectivity/source/drivers/hsqldb/HDriver.cxx +++ b/connectivity/source/drivers/hsqldb/HDriver.cxx @@ -353,14 +353,14 @@ namespace connectivity xComp->addEventListener(this); // we want to close all connections when the office shuts down - static Reference< XTerminateListener> s_xTerminateListener; - if( !s_xTerminateListener.is() ) + static Reference< XTerminateListener> s_xTerminateListener = [&]() { Reference< XDesktop2 > xDesktop = Desktop::create( m_xContext ); - s_xTerminateListener = new OConnectionController(this); - xDesktop->addTerminateListener(s_xTerminateListener); - } + auto tmp = new OConnectionController(this); + xDesktop->addTerminateListener(tmp); + return tmp; + }(); Reference< XComponent> xIfc = new OHsqlConnection( this, xOrig, m_xContext ); xConnection.set(xIfc,UNO_QUERY); m_aConnections.push_back(TWeakPair(WeakReferenceHelper(xOrig),TWeakConnectionPair(sKey,TWeakRefPair(WeakReferenceHelper(xConnection),WeakReferenceHelper())))); diff --git a/connectivity/source/drivers/jdbc/CallableStatement.cxx b/connectivity/source/drivers/jdbc/CallableStatement.cxx index 49c5b0d88bad..720b9c9a8ff1 100644 --- a/connectivity/source/drivers/jdbc/CallableStatement.cxx +++ b/connectivity/source/drivers/jdbc/CallableStatement.cxx @@ -327,12 +327,11 @@ void java_sql_CallableStatement::createStatement(JNIEnv* /*_pEnv*/) // convert Parameter jdbc::LocalRef< jstring > str( t.env(),convertwchar_tToJavaString(t.pEnv,m_sSqlStatement)); - static jmethodID mID(nullptr); - if ( !mID ) + static jmethodID mID = [&]() { static const char * const cSignature = "(Ljava/lang/String;II)Ljava/sql/CallableStatement;"; - mID = t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); - } + return t.pEnv->GetMethodID( m_pConnection->getMyClass(), cMethodName, cSignature ); + }(); if( mID ){ out = t.pEnv->CallObjectMethod( m_pConnection->getJavaObject(), mID, str.get() ,m_nResultSetType,m_nResultSetConcurrency); } //mID diff --git a/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx b/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx index 0c09f95211e0..706d6e064241 100644 --- a/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx +++ b/connectivity/source/drivers/macab/MacabDatabaseMetaData.cxx @@ -736,16 +736,16 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTableTypes( ) ::connectivity::ODatabaseMetaDataResultSet* pResult = new ::connectivity::ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTableTypes); Reference< XResultSet > xRef = pResult; - static ODatabaseMetaDataResultSet::ORows aRows; - static const char aTable[] = "TABLE"; - - if (aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = [&] { + static const char aTable[] = "TABLE"; + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(2); aRow[0] = ODatabaseMetaDataResultSet::getEmptyValue(); aRow[1] = new ORowSetValueDecorator(OUString(aTable)); - aRows.push_back(aRow); - } + tmp.push_back(aRow); + return tmp; + }(); pResult->setRows(aRows); return xRef; } @@ -755,9 +755,9 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( ) ODatabaseMetaDataResultSet* pResult = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); Reference< XResultSet > xRef = pResult; - static ODatabaseMetaDataResultSet::ORows aRows; - if (aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = [&]() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(19); // We support four types: char, timestamp, integer, float @@ -781,27 +781,29 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTypeInfo( ) aRow[17] = ODatabaseMetaDataResultSet::getEmptyValue(); aRow[18] = new ORowSetValueDecorator(sal_Int32(10)); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("TIMESTAMP")); aRow[2] = new ORowSetValueDecorator(DataType::TIMESTAMP); aRow[3] = new ORowSetValueDecorator(sal_Int32(19)); aRow[4] = ODatabaseMetaDataResultSet::getQuoteValue(); aRow[5] = ODatabaseMetaDataResultSet::getQuoteValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("INTEGER")); aRow[2] = new ORowSetValueDecorator(DataType::INTEGER); aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); aRow[15] = new ORowSetValueDecorator(sal_Int32(20)); - aRows.push_back(aRow); + tmp.push_back(aRow); aRow[1] = new ORowSetValueDecorator(OUString("FLOAT")); aRow[2] = new ORowSetValueDecorator(DataType::FLOAT); aRow[3] = new ORowSetValueDecorator(sal_Int32(20)); aRow[15] = new ORowSetValueDecorator(sal_Int32(15)); - aRows.push_back(aRow); - } + tmp.push_back(aRow); + + return tmp; + }(); pResult->setRows(aRows); return xRef; } @@ -943,10 +945,9 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( if (!bTableFound) return xRef; - static ODatabaseMetaDataResultSet::ORows aRows; - - if (aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = [&]() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow(6); MacabRecords *xRecords = m_xConnection->getAddressBook()->getMacabRecords(); @@ -960,14 +961,15 @@ Reference< XResultSet > SAL_CALL MacabDatabaseMetaData::getTables( aRow[3] = new ORowSetValueDecorator(xRecords->getName()); aRow[4] = new ORowSetValueDecorator(OUString(aTable)); aRow[5] = ODatabaseMetaDataResultSet::getEmptyValue(); - aRows.push_back(aRow); + tmp.push_back(aRow); for(i = 0; i < nGroups; i++) { aRow[3] = new ORowSetValueDecorator(xGroups[i]->getName()); - aRows.push_back(aRow); + tmp.push_back(aRow); } - } + return tmp; + }(); pResult->setRows(aRows); return xRef; } diff --git a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx b/connectivity/source/drivers/mork/MDatabaseMetaData.cxx index 0ce5c3e856ca..77d70f7f9093 100644 --- a/connectivity/source/drivers/mork/MDatabaseMetaData.cxx +++ b/connectivity/source/drivers/mork/MDatabaseMetaData.cxx @@ -839,10 +839,9 @@ Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) // in special the metadata of the resultset already returns the right columns ODatabaseMetaDataResultSet* pResultSet = new ODatabaseMetaDataResultSet(ODatabaseMetaDataResultSet::eTypeInfo); Reference< XResultSet > xResultSet = pResultSet; - static ODatabaseMetaDataResultSet::ORows aRows; - - if(aRows.empty()) + static ODatabaseMetaDataResultSet::ORows aRows = [&]() { + ODatabaseMetaDataResultSet::ORows tmp; ODatabaseMetaDataResultSet::ORow aRow; aRow.reserve(19); aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); @@ -866,9 +865,9 @@ Reference< XResultSet > ODatabaseMetaData::impl_getTypeInfo_throw( ) aRow.push_back(ODatabaseMetaDataResultSet::getEmptyValue()); aRow.push_back(new ORowSetValueDecorator(sal_Int32(10))); - aRows.push_back(aRow); - - } + tmp.push_back(aRow); + return tmp; + }(); pResultSet->setRows(aRows); return xResultSet; } diff --git a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx index 6828c471c1ed..f28ec81ff67e 100644 --- a/connectivity/source/drivers/postgresql/pq_baseresultset.cxx +++ b/connectivity/source/drivers/postgresql/pq_baseresultset.cxx @@ -111,8 +111,7 @@ static ::cppu::IPropertyArrayHelper & getResultSetPropertyArrayHelper() "ResultSetType", 6, ::cppu::UnoType<sal_Int32>::get() , 0 )}, true ); - static ::cppu::IPropertyArrayHelper *pArrayHelper = &arrayHelper; - return *pArrayHelper; + return arrayHelper; } BaseResultSet::BaseResultSet( diff --git a/connectivity/source/drivers/postgresql/pq_statement.cxx b/connectivity/source/drivers/postgresql/pq_statement.cxx index 17276c94925f..db99a20910b0 100644 --- a/connectivity/source/drivers/postgresql/pq_statement.cxx +++ b/connectivity/source/drivers/postgresql/pq_statement.cxx @@ -138,9 +138,7 @@ static ::cppu::IPropertyArrayHelper & getStatementPropertyArrayHelper() ::cppu::UnoType<sal_Int32>::get() , 0 )}, true ); - static ::cppu::IPropertyArrayHelper *pArrayHelper = &arrayHelper; - - return *pArrayHelper; + return arrayHelper; } Statement::Statement( const ::rtl::Reference< comphelper::RefCountedMutex > & refMutex, diff --git a/cppuhelper/source/weak.cxx b/cppuhelper/source/weak.cxx index cd3fa5e48dfc..d93cf4d0a7a8 100644 --- a/cppuhelper/source/weak.cxx +++ b/cppuhelper/source/weak.cxx @@ -40,9 +40,7 @@ namespace cppu // this is used to lock all instances of OWeakConnectionPoint and OWeakRefListener as well as OWeakObject::m_pWeakConnectionPoint static Mutex & getWeakMutex() { - static Mutex * s_pMutex = nullptr; - if (! s_pMutex) - s_pMutex = new Mutex(); + static Mutex * s_pMutex = new Mutex(); return *s_pMutex; } diff --git a/cui/source/tabpages/numpages.cxx b/cui/source/tabpages/numpages.cxx index 07b1c912bf7b..df31d118ae28 100644 --- a/cui/source/tabpages/numpages.cxx +++ b/cui/source/tabpages/numpages.cxx @@ -156,17 +156,16 @@ static bool lcl_IsNumFmtSet(SvxNumRule const * pNum, sal_uInt16 nLevelMask) static const vcl::Font& lcl_GetDefaultBulletFont() { - static bool bInit = false; - static vcl::Font aDefBulletFont("OpenSymbol", "", Size(0, 14)); - if(!bInit) - { - aDefBulletFont.SetCharSet( RTL_TEXTENCODING_SYMBOL ); - aDefBulletFont.SetFamily( FAMILY_DONTKNOW ); - aDefBulletFont.SetPitch( PITCH_DONTKNOW ); - aDefBulletFont.SetWeight( WEIGHT_DONTKNOW ); - aDefBulletFont.SetTransparent( true ); - bInit = true; - } + static vcl::Font aDefBulletFont = [&]() + { + vcl::Font tmp("OpenSymbol", "", Size(0, 14)); + tmp.SetCharSet( RTL_TEXTENCODING_SYMBOL ); + tmp.SetFamily( FAMILY_DONTKNOW ); + tmp.SetPitch( PITCH_DONTKNOW ); + tmp.SetWeight( WEIGHT_DONTKNOW ); + tmp.SetTransparent( true ); + return tmp; + }(); return aDefBulletFont; } |