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