Kaydet (Commit) 85acc270 authored tarafından Noel Grandin's avatar Noel Grandin

improve function-local statics in sal

Change-Id: I0853cf13162bae44cf8a5c44a4546a73f05772d9
Reviewed-on: https://gerrit.libreoffice.org/63780
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst eea439b4
......@@ -879,19 +879,7 @@ static osl_TStamp OslProfile_getFileStamp(osl_TFile* pFile)
static bool OslProfile_lockFile(const osl_TFile* pFile, osl_TLockMode eMode)
{
struct flock lock;
/* boring hack, but initializers for static vars must be constant */
static bool bIsInitialized = false;
static bool bLockingDisabled;
if ( !bIsInitialized )
{
sal_Char* pEnvValue;
pEnvValue = getenv( "STAR_PROFILE_LOCKING_DISABLED" );
bLockingDisabled = pEnvValue != nullptr;
bIsInitialized = true;
}
static bool const bLockingDisabled = getenv( "STAR_PROFILE_LOCKING_DISABLED" ) != nullptr;
if (pFile->m_Handle < 0)
{
......
......@@ -327,10 +327,7 @@ typedef BOOL (WINAPI *GetModuleInformation_PROC)(
static bool osl_addressGetModuleURL_NT_( void *pv, rtl_uString **pustrURL )
{
bool bSuccess = false; /* Assume failure */
static HMODULE hModPsapi = nullptr;
if ( !hModPsapi )
hModPsapi = LoadLibraryW( L"PSAPI.DLL" );
static HMODULE hModPsapi = LoadLibraryW( L"PSAPI.DLL" );
if ( hModPsapi )
{
......
......@@ -35,18 +35,14 @@ sal_Bool SAL_CALL osl_getSystemTime(TimeValue* pTimeVal)
typedef VOID (WINAPI *GetSystemTimePreciseAsFileTime_PROC)(LPFILETIME);
static HMODULE hModule = nullptr;
static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = nullptr;
OSL_ASSERT(pTimeVal != nullptr);
if ( !hModule )
static GetSystemTimePreciseAsFileTime_PROC pGetSystemTimePreciseAsFileTime = [&]()
{
hModule = GetModuleHandleW( L"Kernel32.dll" );
if ( hModule )
pGetSystemTimePreciseAsFileTime = reinterpret_cast<GetSystemTimePreciseAsFileTime_PROC>(
HMODULE hModule = GetModuleHandleW( L"Kernel32.dll" );
return reinterpret_cast<GetSystemTimePreciseAsFileTime_PROC>(
GetProcAddress(hModule, "GetSystemTimePreciseAsFileTime"));
}
}();
// use ~1 microsecond resolution if available
if (pGetSystemTimePreciseAsFileTime)
......
......@@ -4922,8 +4922,7 @@ namespace osl_Directory
static OUString const & get_test_path()
{
static OUString test_path;
if (test_path.isEmpty())
static OUString test_path = [&]()
{
OUString tmp;
osl::FileBase::RC rc = osl::FileBase::getTempDirURL(tmp);
......@@ -4962,14 +4961,16 @@ namespace osl_Directory
#endif
tmp_x += OString(TEST_PATH_POSTFIX);
rc = osl::FileBase::getFileURLFromSystemPath(OStringToOUString(tmp_x, RTL_TEXTENCODING_UTF8), test_path);
OUString tmpTestPath;
rc = osl::FileBase::getFileURLFromSystemPath(OStringToOUString(tmp_x, RTL_TEXTENCODING_UTF8), tmpTestPath);
CPPUNIT_ASSERT_EQUAL_MESSAGE
(
"Cannot convert the system path back to an URL",
osl::FileBase::E_None, rc
);
}
);
return tmpTestPath;
}();
return test_path;
}
......
......@@ -155,10 +155,9 @@ static bool getFromCommandLineArgs(
{
OSL_ASSERT(value);
static NameValueVector *pNameValueVector = nullptr;
if (!pNameValueVector)
static NameValueVector nameValueVector = [&]()
{
static NameValueVector nameValueVector;
NameValueVector tmp;
sal_Int32 nArgCount = osl_getCommandArgCount();
for(sal_Int32 i = 0; i < nArgCount; ++ i)
......@@ -189,18 +188,18 @@ static bool getFromCommandLineArgs(
nameValue.sValue = nameValue.sValue.copy(0,nameValue.sValue.getLength()-1);
}
nameValueVector.push_back( nameValue );
tmp.push_back( nameValue );
}
}
rtl_uString_release( pArg );
}
pNameValueVector = &nameValueVector;
}
};
return tmp;
}();
bool found = false;
for(NameValueVector::iterator ii = pNameValueVector->begin();
ii != pNameValueVector->end();
for(NameValueVector::iterator ii = nameValueVector.begin();
ii != nameValueVector.end();
++ii)
{
if ((*ii).sName == key)
......
......@@ -40,12 +40,7 @@ static void rtl_str_hash_free(StringHashTable *pHash);
static StringHashTable * getHashTable()
{
static StringHashTable *pInternPool = nullptr;
if (!pInternPool)
{
static StringHashTable* pHash = rtl_str_hash_new(1024);
pInternPool = pHash;
}
static StringHashTable* pInternPool = rtl_str_hash_new(1024);
return pInternPool;
}
......
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